Python Unit - 3( c ) Tuple
Python Unit - 3( c ) Tuple
INTRODUCTION TO PYTHON
PROGRAMMING
BCA – II YEAR
IV SEMESTER
By:-
Vinita Thanvi
Assistant Professor
Lucky Institute of Professional Studies
Tuple items are indexed, the first item has index [0], the second item has index [1]
etc.
Ordered
When we say that tuples are ordered, it means that the items have a defined order,
and that order will not change.
Unchangeable
Tuples are unchangeable, meaning that we cannot change, add or remove items
after the tuple has been created.
Allow Duplicates
Since tuples are indexed, they can have items with the same value:
When you create a tuple with only one element, you need a trailing
comma to distinguish it from a regular parenthesis.
single_element_tuple = (5,)
print(single_element_tuple) # Output: (5)
You can create a tuple without parentheses by using just commas, but
this is usually less readable.
tuple_without_parentheses = 1, 2, 3
print(tuple_without_parentheses) # Output: (1, 2, 3)
empty_tuple = ()
print(empty_tuple) # Output: ()