The string Module
The string
module supplies functions that duplicate each method of string objects, as covered in Methods of String Objects. Each function takes the (plain or Unicode) string object as its first argument. Module string
also supplies several useful plain-string attributes:
ascii_letters
The string
ascii_lowercase+ascii_uppercase
ascii_lowercase
The string
'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase
The string
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
digits
The string
'0123456789'
hexdigits
The string
'0123456789abcdefABCDEF'
letters
The string
lowercase+uppercase
lowercase
A string containing all characters that are deemed lowercase letters: at least
'abcdefghijklmnopqrstuvwxyz'
, but more letters (e.g., accented ones) may be present, depending on the active localeoctdigits
The string
'01234567'
punctuation
The string
'!"#$%&\'( )*+,-./:;<=>?@[\\]^_'{|}~'
(i.e., all ASCII characters that are deemed punctuation characters in the'C'
locale; does not depend on which locale is active)printable
The string of those characters that are deemed printable (i.e., digits, letters, punctuation, and whitespace)
uppercase
A string containing all characters that are deemed uppercase letters: at least
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
, but more letters (e.g., accented ones) may be present, depending on the active localewhitespace
A string containing all characters that are deemed whitespace: at least space, tab, linefeed, and carriage return, but more characters (e.g., certain control characters) may be present, depending ...
Get Python in a Nutshell, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.