使用时出错字符串.标点符号python

2024-10-02 10:25:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着用字符串.标点符号函数,我在python3.5版本中做。以下是我的代码:

import string
def check(text):
    x=set(text.punctuation())

我有以下错误

^{pr2}$

请帮助您正确使用此函数。我甚至尝试过使用ispunct()函数。在

我试图解决这个问题,如下面的链接所示,但无法解决。在

Best way to strip punctuation from a string in Python


Tags: 函数字符串代码textimport版本stringdef
1条回答
网友
1楼 · 发布于 2024-10-02 10:25:07

punctuationstring模块的方法,不是字符串对象属性。在

>>> import string
>>> 
>>> string.punctuation
'!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'

如果要从文本中获取punctuation,可以使用set中的生成器表达式:

^{pr2}$

相关问题 更多 >

    热门问题