我知道如何去除字符串中的所有标点符号。
import string
s = '.$ABC-799-99,#'
table = string.maketrans("","") # to remove punctuation
new_s = s.translate(table, string.punctuation)
print(new_s)
# Output
ABC79999
如何在Python中去除所有前导和尾随标点符号?期望的结果为'. $ ABC-799-99,#'
是'ABC-799-99'
。
s.strip(string.punctuation)
的翻译是:去除字符串s
开头和结尾处的标点符号(punctuation)。 - zondo