【问题标题】:Why doesn't .isascii() work on google colab?为什么 .isascii() 在 google colab 上不起作用?
【发布时间】:2020-11-27 04:17:30
【问题描述】:

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

AttributeError: 'str' object has no attribute 'isascii'

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

thisstr = "Hoho"
k = thisstr.isascii()
print(k)

【问题讨论】:

  • 我在我的机器上的 Python 控制台中运行了您的代码,结果为真,而 Google Colab 则抛出了一个错误。太奇怪了。

标签: python python-3.x google-colaboratory


【解决方案1】:

Google Colab 中的 python 版本是 3.6,而isascii 方法是在 Python 3.7 中引入的。引用What's new in Python 3.7:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-09-28
    • 2022-11-02
    • 1970-01-01
    • 2020-05-29
    • 1970-01-01
    • 2022-06-21
    • 1970-01-01
    相关资源
    最近更新 更多