A tuple is a sequence of values that are nested into one function. These elements can be strings, number, and even tuples. You can have many types of elements within the same tuple, for example:

Colors = (‘red’, ‘blue’, ’yellow’ )
Numbers = ( 1, 2, 3 )
List = ( 4, (5, 6))
Other = ( ‘red’, 2, (5, 6) )

      As you can see, tuples are pretty much like a list; what differentiates them is that tuples cannot be mutable. For creating a tuple you need to establish the name of the tuple followed by an equal sign (which means ‘assignment’). After the equal sign you start naming the elements included in the list. These elements are nested inside parenthesis () and separated by commas. If the element being established is a string, it needs to be between quotation marks.

     For printing the whole tuple you type the command print() and between the parenthesis you type the name of the tuple. For printing just one element of the tuple you type the command print() and between the parenthesis you type the name of the tuple followed by the number of the element between square brackets.

NOTE: The elements on a tuple are numbered starting from 0

     For knowing how many elements a tuple contains, you can use the command len(), between the parenthesis you type the name of the tuple.


     Also, you can add one tuple to another and create a new tuple. For that, you need to type the name of the tuple you are creating followed by an equal sign, followed by the name of the first tuple and the addition sign followed by the second tuple you will adding.

CC BY 4.0 Tuples by Frida Diaz is licensed under a Creative Commons Attribution 4.0 International License.