Tuple In Python
Tuples are ordered list of comma separated values and it is immutable.
Different data types can be stored in a tuple.
Tuples are iterable, they can be iterated over with a for loop.
Tuples are useful for returning a small list of values from a function.
Extracting the individual values from a tuple is known as unpacking.
The commas between the values are the operator which determines the value to be a tuple.
Optionally, parentheses can be wrapped around the tuple, but the parentheses do not define it to be a tuple.
For empty tuples, empty parentheses are used.
Element access with square brackets and zero-based index t[index].
Can’t use one object in parentheses a single element tuple, for example, use (321,) instead of (321).
For a single element tuple include a trailing comma.
Use the tuple(iterable) constructor to create tuples from other iterable series of objects.
The in and not in operators can be used with tuples and other collection types for membership testing.
5 in (2,5,6)
5 not in (4,6,7)
Delimiting parentheses are optional for one or more elements.
Tuples are useful for multiple return values.
Creating tuple and performing some operation on that: