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