我需要一些更多的帮助。基本上,我试图返回删除所有非空格和非字母数字字符的用户输入。我做了这么多的代码,但我不断收到错误...如何从字符串中删除标点符号? (Python)
def remove_punctuation(s):
'''(str) -> str
Return s with all non-space or non-alphanumeric
characters removed.
>>> remove_punctuation('a, b, c, 3!!')
'a b c 3'
'''
punctuation = '''''!()-[]{};:'"\,<>./[email protected]#$%^&*_~'''
my_str = s
no_punct = ""
for char in my_str:
if char not in punctuation:
no_punct = no_punct + char
return(no_punct)
我不知道我在做什么错。任何帮助表示赞赏!
请描述或发布错误。没有人可以帮助你,否则 – ytpillai
所有这些引号是怎么回事?尝试更类似于''!() - [] {};:\'“\,<> ./[email protected]#$%^&*_〜'' –
”Python Shell,提示2,第1行 语法错误:无效的语法:,第1行,第31位“是我的特定错误 –