The python String module is a computer language that is widely used and has powerful functions in actual operations. However, no one knows how to simply use the python string module, the following describes the actual usage of the python String module.
We recommend that you use the str class instead of the string module. The String module provides common string processing functions. These functions can be found in the str class; some constants provided in the python String module are still very useful.
String member constant:
- ascii_letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHI
JKLMNOPQRSTUVWXYZ'
- ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
- ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
- letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghij
klmnopqrstuvwxyz'
- lowercase = 'abcdefghijklmnopqrstuvwxyz'
- uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
- digits = '0123456789'
- hexdigits = '0123456789abcdefABCDEF'
- octdigits = '01234567'
- whitespace = '\t\n\x0b\x0c\r '
- punctuation = '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
- printable = '0123456789abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTU...
Member functions:
- atof(s) -> float
- >>> atof = string.atof
- >>> atof("3.14")
- 3.1400000000000001
- >>> atof("1")
Integer that can be processed
- 1.0
- >>> atof("-9")
It can process plus or minus signs. You cannot add 'F' to the end of a numeric character'
- Traceback (most recent call last):
- File "<pyshell#24>", line 1, in <module>
- atof("3.14f")
- File "C:\Python26\lib\string.py", line 386, in atof
- return _float(s)
- ValueError: invalid literal for float(): 3.14f
- >>> atof("s3.14")
Throw an exception when an error occurs.
- Traceback (most recent call last):
- File "<pyshell#26>", line 1, in <module>
- atof("s3.14")
- File "C:\Python26\lib\string.py", line 386, in atof
- return _float(s)
- ValueError: invalid literal for float(): s3.14
- atoi(s [,base]) -> int
-
Converts string S to an integer, and base is 10 by default. The above article introduces the python String module.