Creating a Tuple in Python
Tuples can be created simply using parentheses. To do this, simply declare a variable and enclose its value in parentheses. Let's create an empty tuple:
tpl = ()
Now we can list the elements of a tuple inside parentheses:
tpl = ('a', 'b', 'c')
Tuples can contain elements of different types: strings, numbers, booleans, lists:
tpl1 = ('1', '2', '3')
tpl2 = (1, 2, 3)
tpl3 = (True, False)
tpl4 = (['a', 'b'], ['c', 'd'])
Given a variable:
tst = (12, 34, 45)
Tell me what type of data it is.
Given a variable:
tst = [1, 2, 3]
Tell me what type of data it is.
Given a variable:
tst = ([1, 2, 3], True, 'a', 'b')
Tell me what type of data it is.