a list. Then find the sum of all values. Tuples . Introduction to Tuples Tuples consists of a number of values separated by comma and enclosed within parentheses.
Tuple is similar to list, values in a list can be changed but not in a tuple. The term Tuple is originated from the Latin word represents an abstraction of the sequence of numbers: single( ), double( ), triple( ), quadruple( ), quintuple( ), sextuple( ), septuple( ), octuple( ), ..., n‑tuple, ..., . . Comparison of Tuples and list .
The elements of a list are changeable (mutable) whereas the elements of a tuple are unchangeable (immutable), this is the key difference between tuples and list. . The elements of a list are enclosed within square brackets. But, the elements of a tuple are enclosed by paranthesis.
. Iterating tuples is faster than list. 12th Computer Chapter - - Lists, Tuples, Sets and Dictionary . .
Creating Tuples Creating tuples is similar to list. In a list, elements are defined within square brackets, whereas in tuples, they may be enclosed by parenthesis. The elements of a tuple can be even defined without parenthesis. Whether the elements defined within parenthesis or without parenthesis, there is no differente in it's function.
Syntax: # Empty tuple = ( ) # Tuple with n number elements = (E1, E2, E2 ……. En) # Elements of a tuple without parenthesis = E1, E2, E3 ….. En >>> MyTup1 = ( , , , 'A', 'E', 'I', "Tamil") >>> print(MyTup1) ( , , , 'A', 'E', 'I', 'Tamil') >>> MyTup2 = , , , 'A', 'E', 'I', "Tamil" >>> print (MyTup2) ( , , , 'A', 'E', 'I', 'Tamil') Example (i) Creating tuples using tuple( ) function The tuple() function is used to create Tuples from a list. When you create a tuple, from a list, the elements should be enclosed within square brackets.
Syntax: = tuple( [list elements] ) >>> MyTup3 = tuple( [ , , ] ) >>> print(MyTup3) ( , , ) >>> type (MyTup3) <class ‘tuple’> Example 12th Computer Chapter - - Type ( ) function