- Complete Python Bootcamp: Go from zero to hero in Python
- Complete Python Web Course: Build 8 Python Web Apps
A tuple in Python is a collection that cannot be modified. A tuple is defined using parenthesis.
A tuple with one item ( a comma is needed in the end ):
x = (1,)
A tuple with multiple items:
x = (1,2,3,4)
To access individual elements, we use square brackets. To print the first element (Python starts counting from zero):
To print the second element:
To print the last element, you can count from the back using the minus sign.