python 列表的定义:
中括号、内容用, 隔开 names = ["water","tony","hello","walt","zhangsan"],值的类型不需要是同一种数据类型
列表取值: 使用索引方式取 names[0]
分别使用while循环和for循环遍历列表
while循环:
names = ["water", "tony", "hello", "walt", "zhangsan"]
i = 0
while i < len(names):
print(names[i])
i += 1
for 循环
for i in names:
print(i)
列表的常见操作:增删改查
movies = ["加勒比海盗", '泰坦尼克号', '速度与激情']
for name in movies:
print(name)
结果:
<添加数据>:append