czh18398223563 发表于 2021-1-29 10:51:31

用removeprefix(prefix)报错,有没有兄弟知道是怎么回事?

python3.8.5   
str1='今天天气真好'
>>> str1.removeprefix('今天')
Traceback (most recent call last):
File "<pyshell#61>", line 1, in <module>
    str1.removeprefix('今天')
AttributeError: 'str' object has no attribute 'removeprefix'

suchocolate 发表于 2021-1-29 10:56:06

本帖最后由 suchocolate 于 2021-1-29 10:57 编辑

python3.9才有
https://docs.python.org/zh-cn/3.9/whatsnew/3.9.html#new-string-methods-to-remove-prefixes-and-suffixes

yuxijian2020 发表于 2021-1-29 10:56:18

百度翻译:
AttributeError:“str”对象没有“removeprefix”属性

basketmn 发表于 2021-1-29 10:57:53

貌似这是3.9才有的
页: [1]
查看完整版本: 用removeprefix(prefix)报错,有没有兄弟知道是怎么回事?