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

标签 python python-3.x google-colaboratory

我正在使用 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, and bytearray 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/

相关文章:

Python:为什么我的数据库不显示在这个窗口中?

Python:凯撒密码

python-3.x - 如何禁用cloudscraper Python中的安全证书检查

python - python 3 中的 Expat 解析

python - 如何从已安装的云端硬盘文件夹中永久删除?

python - 如何在django中的过滤器类中设置后端过滤器范围

python - 发出打印字符串的单个字母

python - 可以属于几种可能模型之一的 SQLAlchemy 外键?

google-drive-api - 从Google Colab中的驱动器读取文件

python - 为什么隐蔽的 Tensorflow 升级到 2.9.1 会破坏使用 GPU 而不是 CPU 的 Google Colab Jupyter 笔记本?