# 一般不用while遍历list
a = [1,2,3,4,5,6]
length = len(a)
# indx表示的是list的下标
indx = 0
while indx < length:...content
通过简单的方法创作列表
# for 创建
a = ['a', 'b', 'c']
# 用List a创建一个List b
# 下面的代码的含义是,对于所有a中的元素,逐个放入新列表b中...b = [i for i in a]
print(b)
['a', 'b', 'c']
# 对a中所有元素乘以10,生成一个新List
a = [1, 2, 3, 4, 5]
# 用List a创建一个...:将其他格式的数据转换成List
a = [1,2,3]
print(list(a))
[1, 2, 3]
s = "I love you"
print(list(s))
['I', ' ', 'l',...'o', 'v', 'e', ' ', 'y', 'o', 'u']
# 把range产生的内容转换成list
print(list(range(12,19)))
[12, 13, 14, 15, 16