我知道如何删除字符串中的所有标点符号。
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'
。
Tags:
你做的正是你在问题中提到的,你只是str.strip而已。
输出:
str.strip可能需要删除多个字符。
如果您只想删除前导标点,可以str.lstrip:
或rstrip任何尾随标点:
相关问题 更多 >
编程相关推荐