list()
1. 无参数
empty_list = list()
print(empty_list) # 输出 []2. 可迭代对象
# 字符串
print(list("hello")) # 输出 ['h', 'e', 'l', 'l', 'o']
# 元组
print(list((1, 2, 3))) # 输出 [1, 2, 3]
# 集合
print(list({1, 2, 3})) # 输出 [1, 2, 3](顺序可能不同)
# 字典(默认使用键)
print(list({"a": 1, "b": 2})) # 输出 ['a', 'b']3. 字典的键或值
4. 生成器或迭代器
5. 其他类型
6. 自定义可迭代对象
总结
最后更新于