Traversing & Accessing a Tuple


☞ We can traverse a tuple using two ways.

1. Using Index
2. Without Using Index

Using Index

Example 1 :
#Traversing a tuple using for loop
T = (10, 20, 30, 40)
for i in range(len(T)):
    print(T[i])
Output
 
10
20
30
40
Example 2 :
#Traversing a tuple using while loop
T = (10, 20, 30, 40)
i = 0
while i < len(T):
    print(T[i])
    i = i + 1
Output
 
10
20
30
40

Without Using Index

Example :
T = (10, 20, 30, 40)
for i in T:
    print(i)
Output
 
10
20
30
40