In Python, the tuple() function is used to convert an iterable object into a tuple.
Function Syntax
tuple([iterable])
Parameter:
iterable: An iterable object. Creates an empty tuple if omitted.
Returns a tuple (an immutable sequence).
Examples of the tuple() Function
Creating an empty tuple:
tpl1 = ()
tpl2 = tuple()
Creating a tuple from an iterable object:
# Create from a list
lst = [1, 2, 3]
print(tuple(lst)) #(1, 2, 3)
# Create from a dictionary (by default, obtains a tuple of keys)
dict1 = {'a':1,'b':2}
print(tuple(dict1)) ('a', 'b')
# Create from dictionary values
print(tuple(dict1.values())) # (1, 2)