-
delete ":"
123
import
string
allchars
=
string.maketrans('
','
')
options
=
options.translate(allchars,
':'
)
-
Replace 'e' with 'a', delete 'o'
1234
import
string
aTob
=
string.maketrans(
'e'
,
'a'
)
s
=
'hello python'
print
s.translate(aTob,
'o'
)
Output:
1 | hall pythn |
Python Cook 1.9 简化使用string的translate方法
See Also String.replace
Hide Comments