[英]Proper syntax to pass multiple arguments to a method in Python 3?
I'm attempting to remove all punctuation AND digits from a string using the method str.maketrans(). 我正在尝试使用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:
Python 3的文档指出适当的语法为:
str.maketrans( x [, y [, z] ] )
Is there a recommended syntax to incorporate multiple arguments for 'z'? 是否有建议的语法为“ z”合并多个参数?
对于后代,可以使用“ +”作为解决方案:
a_string = a_string.translate(str.maketrans('', '', string.punctuation + string.digits))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.