1 元组 列表基本用法
将列表或者元组里的元素依次输出:
#元组
a_tuple=(1,23,43,5454,656,43)
b_tuple=23,434,5,3,2,3
#列表
a_list=[34,24,'qw',87,3,44,5,23]
for content in a_list:
print(content)
for content in a_tuple:
print(content)
输出序号和内容:
#列表
a_list=[34,24,'qw',87,3,44,5,23]
for index in range(len(a_list)):
print(" the index",index,"number is",a_list[index])
运行结果:
D:\PycharmProjects\pythonProject\venv\Scripts\python.exe D:/PycharmProjects/pythonProject/hello.py
the index 0 number is 34
the index 1 number is 24
the index 2 number is qw
the index 3 number is 87
the index 4 number is 3
the index 5 number is 44
the index 6 number is 5
the index 7 number is 23
2 列表
添加一个值到列表里:
#列表
a_list=[34,24,'qw',87,3,44,5,23]
a_list.append(0)
print(a_list)<