1. 进入terminal输入:python
2. 导入string module :import string
3. 显示string module中的所有方法: dir(string)
4. 查看string中的某个方法怎么使用:help(string.方法名),按q退出
GrandKai:~ GrandKai$ python3
Python 3.5.2 (default, Oct 14 2016, 15:01:45)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.38)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import string
>>> dir(string)
['Formatter', 'Template', '_TemplateMetaclass', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '_float', '_idmap', '_idmapL', '_int', '_long', '_multimap', '_re', 'ascii_letters', 'ascii_lowercase', 'ascii_uppercase', 'atof', 'atof_error', 'atoi', 'atoi_error', 'atol', 'atol_error', 'capitalize', 'capwords', 'center', 'count', 'digits', 'expandtabs', 'find', 'hexdigits', 'index', 'index_error', 'join', 'joinfields', 'letters', 'ljust', 'lower', 'lowercase', 'lstrip', 'maketrans', 'octdigits', 'printable', 'punctuation', 'replace', 'rfind', 'rindex', 'rjust', 'rsplit', 'rstrip', 'split', 'splitfields', 'strip', 'swapcase', 'translate', 'upper', 'uppercase', 'whitespace', 'zfill']
>>>help(string.Formatter)
string中几个常用的方法
string.atof(s)# Convert to float
string.atoi(s)# Convert to integer
string.atol(s)# Convert to long
string.count(s,pattern)# Count occurrences of pattern in s
string.find(s,pattern)# Find pattern in s
string.split(s, sep)# String a string
string.join(strlist, sep) # Join a list of string
string.replace(s,old,new) # Replace occurrences of old with new