The tuple function
The tuple function creates a new tuple from the object specified in the parameter.
Syntax
tuple(the object from which we create a tuple)
Example
Let's make a tuple using the tuple function:
txt = 'abcde'
tlp = tuple(txt)
print(tlp)
Result of code execution:
('a', 'b', 'c', 'd', 'e')
Example
Now let's make a dictionary from the number:
num = 1234
tlp = tuple(num)
print(tlp)
After executing the code, the function will return us an error, since the number is not an iterable object:
TypeError: 'int' object is not iterable
Example
Let's use the tuple function to make a tuple from a list:
lst = ['a', 'b', 'c', 'd']
tlp = tuple(lst)
print(tlp)
Result of code execution:
('a', 'b', 'c', 'd')