我正在使用 Windows 10 和 Pycharm IDE。.isascii()
在 google colab 上不起作用是否有原因?当我在 google colab 上尝试代码片段时,我得到:
AttributeError: 'str' object has no attribute 'isascii'
如果我在我的 IDE 上尝试相同的代码,我会得到 True
。thisstr = "Hoho"
k = thisstr.isascii()
print(k)
最佳答案
Google Colab 中的 Python 版本是 3.6,而 Python 3.7 中引入了 isascii
方法。引用 What's new in Python 3.7 :
str
,bytes
, andbytearray
gained support for the new isascii() method, which can be used to test if a string or bytes contain only the ASCII characters.
关于python - 为什么 .isascii() 在 google colab 上不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63291420/