【发布时间】:2016-05-14 00:50:27
【问题描述】:
我知道如何删除字符串中的所有标点符号。
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) -
我在 Google 上搜索了您问题的标题,链接的副本是第一个结果,其中包含您正在寻找的确切解决方案。请在未来做更多的研究。
-
@TigerhawkT3,谢谢,我对 SO 进行了研究。
-
SO 的搜索不是很好。下次试试 Google。
-
@TigerhawkT3,我会记住的。再次感谢。
标签: python strip punctuation