What are tuples?

A tuple is a collection and iterable which is ordered and unchangeable.

Syntax
This is how you create a tuple: aTuple = ("Thing01", "Thing02", "Thing03") print(aTuple) ('Thing01', 'Thing02', 'Thing03') You can access items in a tuple using number indexes : print(aTuple[2]) Thing03
 * 1) Returns :
 * 1) Returns:

The difference between lists and tuples
tupple_colours = ('red', 'blue', 'green') list_colours = ['red', 'blue', 'green']
 * Tuples are immutable (cannot change the values in place) where lists are mutable (can be changed in place).
 * Syntax :
 * Tuples do not need to be copied, since tuples are immutable.
 * Tuples are smaller in size than lists.
 * Tuples are heterogeneous whereas lists are homogeneous. Meaning that different data can be stored in a single tuple while lists must have all the same data types stored in them.
 * Lists are for varying length, whereas tuples have fixed length.
 * Tuples show structure where lists show order.
 * Tuples are comparable and hashable so we can sort lists of them and use tuples as key values in dictionaries. (hashable: A type that has a hash function. Immutable types like integers, floats, and strings are hashable; mutable types like lists and dictionaries are not.)
 * Tuples can be used as values in sets, lists can not.

Tuples as dictionary keys
Some tuples can be used as dictionary keys (specifically, tuples that contain immutable values like strings, numbers, and other tuples). E.g : tupleDict = {('this', 'is'): 15, ('an', 'example'): 19, ('tupleDict'): 24} Lists can never be used as dictionary keys, because lists are not immutable. E.g : listDict = {['this', 'is']: 15, ['an', 'example']: 19, ['tupleDict']: 24} TypeError: unhashable type: 'list'
 * 1) Returns:

Tuples as values in sets
Tuples can be used as values in sets : tupleSet = {('this', 'is'), ('an', 'example'), ('example', 'snippet')} print(tupleSet) print(type(tupleSet)) {('example', 'snippet'), ('an', 'example'), ('this', 'is')}  Lists can not : listSet = {['this', 'is'], ['an', 'example'], ['example', 'snippet']} TypeError: unhashable type: 'list'
 * 1) Returns:
 * 1) Returns: