str
is a built-in function (actually a class) which converts its argument to a string. string
is a module which provides common string operations.
>>> str
<class 'str'>
>>> str(42)
'42'
>>> import string
>>> string
<module 'string' from '/usr/lib/python3.1/string.py'>
>>> string.digits
'0123456789'
Put another way, str
objects are a textual representation of some object o
, often created by calling str(o)
. These objects have certain methods defined on them. The module string
provides additional functions and constants that are useful when working with strings.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…