An Alternative Way to Create a Tuple in Python
An alternative way to create a tuple is to use the tuple
function. The required elements or objects are passed to its parameter.
Let's make a tuple by passing a string to the function parameter:
tpl = tuple('abcde')
print(tpl) # ('a', 'b', 'c', 'd', 'e')
However, numbers cannot be passed to the tuple
function:
tpl = tuple(1234)
print(tpl) # will display an error
Given a variable:
tst = '12345'
Create a tuple from it.
Given a string:
txt = '12345'
Split this string into the following tuple:
tpl = ('1', '2', '3', '4', '5')
Given a variable:
tst = 98765
Create a tuple from it:
tpl = ('9', '8', '7', '6', '5')