Python get value from tuple | Example code

The get value from the Python tuple use index number inside square brackets [ ].

tuple[index]

Example get value from the tuple in Python

Simple example code.

Get a single value from the tuple

tup = ("Python", "Java", "SQL")

print(tup[1])

Output:

Python get value from tuple

Get all values from a tuple

Use for loop to iterate through tuple and get every value.

tup = ("Python", "Java", "SQL")

for x in tup:
    print(x)

Output:

Python
Java
SQL

Get item index with the value from a tuple in python

Use for loop and index method for it.

tup = ("Python", "Java", "SQL")

for x in tup:
    print(tup.index(x), x)

Output:

0 Python
1 Java
2 SQL

Do comment if you have any doubts and suggestions on this Python tuple tutorial.

Note: IDE: PyCharm 2021.1.3 (Community Edition)

Windows 10

Python 3.7

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.