小编Fal*_*ble的帖子

list[str] 是可迭代的吗?

Python 3.10 不这么认为:

Python 3.10.6 | packaged by conda-forge | (main, Aug 22 2022, 20:38:29) [Clang 13.0.1 ] \
    on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from typing import Iterable
>>> isinstance(list[str], Iterable)
False
>>> list(list[str])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'types.GenericAlias' object is not iterable
Run Code Online (Sandbox Code Playgroud)

Python 3.11 认为它是:

Python 3.11.0 | packaged by conda-forge | (main, Jan 15 2023, 05:44:48) [Clang 14.0.6 ] \
    on darwin
Type …
Run Code Online (Sandbox Code Playgroud)

python python-internals python-typing

8
推荐指数
2
解决办法
993
查看次数

标签 统计

python ×1

python-internals ×1

python-typing ×1