为什么 .isascii() 在 google colab 上不起作用?

JBB*_*JBB 4 python python-3.x google-colaboratory

我正在使用 Windows 10 和 Pycharm IDE。有.isascii()没有在 google colab 上不起作用的原因?当我在 google colab 上尝试代码片段时,我得到:

AttributeError: 'str' object has no attribute 'isascii'
Run Code Online (Sandbox Code Playgroud)

如果我在我的 IDE 上尝试相同的代码,我会得到True.

thisstr = "Hoho"
k = thisstr.isascii()
print(k)
Run Code Online (Sandbox Code Playgroud)

Aso*_*cia 11

Google Colab 中的 Python 版本是 3.6,而isasciiPython 3.7 中引入了方法。引用Python 3.7 中的新增内容

str, bytes, 并bytearray获得了对新 isascii() 方法的支持,该方法可用于测试字符串或字节是否仅包含 ASCII 字符。