元组其实跟列表差不多,也是存一组数,只不是它一旦创建,便不能再修改,所以又叫只读列表
语法
1
|
names = ( "alex" , "jack" , "eric" ) |
它只有2个方法,一个是count,一个是index,完毕。
product_list = [
('Iphone',5800),
('Mac Pro',9800),
('Bike',800),
('Watch',10600),
('Coffee',31),
('Alex Python',120),
]
for index,item in enumerate(product_list):
#print(product_list.index(item),item)
print(index,item)
结果:
0 ('Iphone', 5800)
1 ('Mac Pro', 9800)
2 ('Bike', 800)
3 ('Watch', 10600)
4 ('Coffee', 31)
5 ('Alex Python', 120)