How to use string constants in Python
Created
Modified
String Constants in Python
The constants defined in this module are:
String constants:
string.ascii_lettersThe concatenation of the ascii_lowercase and ascii_uppercase constants described below. This value is not locale-dependent.string.ascii_lowercaseThe lowercase letters 'abcdefghijklmnopqrstuvwxyz'. This value is not locale-dependent and will not change.string.ascii_uppercaseThe uppercase letters 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'. This value is not locale-dependent and will not change.string.digitsThe string '0123456789'.string.hexdigitsThe string '0123456789abcdefABCDEF'.string.octdigitsThe string '01234567'.string.punctuationString of ASCII characters which are considered punctuation characters in the C locale: !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~.string.printableString of ASCII characters which are considered printable. This is a combination of digits, ascii_letters, punctuation, and whitespace.string.whitespaceA string containing all ASCII characters that are considered whitespace. This includes the characters space, tab, linefeed, return, formfeed, and vertical tab.
Use of ascii_lowercase Constant
#!/usr/bin/env python3
import string
if 'a' in string.ascii_lowercase:
print("Found!")
print(string.ascii_lowercase)
Found! abcdefghijklmnopqrstuvwxyz
Use of string.digits Constant
#!/usr/bin/env python3
import string
for a in string.digits:
print(a)
0 1 2 3 4 5 6 7 8 9