创建python列表
方法一:直接创建列表
a = [1, 2, 3, 4, 5]
print(a)
/usr/local/bin/python3.8 /Users/sataniya/PycharmProjects.../demo/demo.py
[1, 2, 3, 4, 5]
方法二:使用list方法
a = list("hello")
print(a)
/usr/local/bin/python3.8 /Users...demo.py
['h', 'e', 'l', 'l', 'o']
方法三:使用split方法
a = "hello world".split(" ")
print(a)
/usr/local/bin/python3.8...PycharmProjects/demo/demo.py
['hello', 'world']
方法四:使用列表推导式
a = [x for x in range(10)]
print(a)
/usr/local/bin/python3.8