Skip to content

Python get value from tuple | Example code

  • by

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 or suggestions on this Python tuple tutorial.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

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

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading