tup = (1,2,3,4)
for tup_index in range(len(tup)):
print("index:",tup_index,"content:",tup[tup_index])
zbx@zbxpc:~$ /usr/bin/python3 /home/zbx/桌面/mofan_python.py
index: 0 content: 1
index: 1 content: 2
index: 2 content: 3
index: 3 content: 4
tup = (1,2,3,4)
for tup_index in tup:
print("index:",tup_index,"content:",tup[tup_index-1])#这里不减一就会超出范围
tup = (1,2,3,4)
for tup_index in tup_index:
print("index:",tup_index,"content:",tup[tup_index-1])#这里不减一就会超出范围