Python Tuples
Python Tuples
Tuples allow multiple values to be stored as a collection.
Accessing elements in Python Tuples
To access an element in a Tuple at the given index use tuple[index]
.
Unpacking Python Tuples
When you create a Tuple using the (...)
syntax it's called packing a Tuple.
Python Tuple Operations
To join Tuples use the + operator
Modifying Python Tuples
Tuples are immutable, meaaning that once they are created you can't change them. You can, however, create a new tuple from an existing Tuple, and in doing so modify the result. This is generally achieved by converting the Tuple to a List, modifying the list, then converting back to a Tuple.
Checking for existence in Python Tuples
To check whether an item exists in a tuple use the in
keyword.
Python Tuple count() Method
Returns the number of times a specified value occurs in a tuple.
Python Tuple index() Method
Searches the tuple for a specified value and returns the position of where it was found.