您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Python:单个可迭代`list(x)`与`[x]`的列表

Python:单个可迭代`list(x)`与`[x]`的列表

[x]是包含 的列表x

list(x)接受x(必须已经可以 !)并将其转换为列表。

>>> [1]  # list literal
[1]
>>> ['abc']  # list containing 'abc'
['abc']
>>> list(1)
# TypeError
>>> list((1,))  # list constructor
[1]
>>> list('abc')  # strings are iterables
['a', 'b', 'c']  # turns string into list!

列表构造函数list(...)-像python的所有内置集合类型(集合,列表,元组,collections.deque等)一样- 可以采用一个可迭代的参数并将其转换。

python 2022/1/1 18:27:25 有211人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶