Python tuple() function
Python tuple() function
The tuple() function in Python creates a tuple object.
Syntax
tuple([iterable])
Parameter
Iterable: This parameter represents a sequence, collection or an iterator object.
Return
This function returns a tuple object.
Example 1
# Python Program explaining # the tuple() function tupVal = tuple(("Monday", "Tusday","Wednesday", "Thursday")) print(tupVal) #creating tuple object tupVal1 = tuple(("apple", "banana", "cherry")) print(tupVal1)
Output
('Monday', 'Tusday', 'Wednesday', 'Thursday') ('apple', 'banana', 'cherry')
Example 2
# Python Program explaining # the tuple() function # when parameter is not passed tupVal = tuple() print(tupVal) # when an iterable is passed list1= [ 11, 12, 13, 14 ] tupVal1 = tuple(list1) print(tupVal1)
Output
() (11, 12, 13, 14)