I'm attempting to remove all punctuation AND digits from a string using the method str.maketrans(). I've succeeded with two lines:
a_string = a_string.translate(str.maketrans('', '', string.punctuation))
a_string = a_string.translate(str.maketrans('', '', string.digits))
I'm curious if this can be done with a single line. The documentation for Python 3 states appropriate syntax is:
str.maketrans( x [, y [, z] ] )
Is there a recommended syntax to incorporate multiple arguments for 'z'?
对于后代,可以使用“ +”作为解决方案:
a_string = a_string.translate(str.maketrans('', '', string.punctuation + string.digits))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.