tup =(1,2,3,4)for tup_index inrange(len(tup)):print("index:",tup_index,"content:",tup[tup_index])
zbx@zbxpc:~$ /usr/bin/python3 /home/zbx/desktop/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])#If there is no minus one here, it will be out of range
tup =(1,2,3,4)for tup_index in tup_index:print("index:",tup_index,"content:",tup[tup_index-1])#If there is no minus one here, it will be out of range
Recommended Posts