Python Tuple - Element access using subscript notation

Access an element of a tuple using subscript notation and print the element values in a while loop

Tuple Updated 17 Sep 2016 1 min read

A tuple element is accessed by using its indices. The index is specfied using subscript notation tuple[element_index].

Example

python
>>> booktypes=("Fiction","Non-Fiction","Science-Fiction","Philosophy","Biographies","Auto-Biographies","History")

>>> index = 0;

>>> count_booktypes=len(booktypes)

>>> while index < count_booktypes:

...     print(booktypes[index])

...     index = index+1

...

Fiction

Non-Fiction

Science-Fiction

Philosophy

Biographies

Auto-Biographies

History