Python tuple() function
The tuple() function in Python creates a tuple object.
Syntax
1 2 3 |
tuple([iterable]) |
Parameter
Iterable: This parameter represents a sequence, collection or an iterator object.
Return
This function returns a tuple object.
Example 1
1 2 3 4 5 6 7 8 9 |
# 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
1 2 3 4 |
('Monday', 'Tusday', 'Wednesday', 'Thursday') ('apple', 'banana', 'cherry') |
Example 2
1 2 3 4 5 6 7 8 9 10 11 |
# 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
1 2 3 4 |
() (11, 12, 13, 14) |