Professional Documents
Culture Documents
Week - 5 Sets and Tuples: Mutability
Week - 5 Sets and Tuples: Mutability
WEEK -5
• Using parenthesis ( )
mytuple = (“apple”, “banana”, “cherry”) # creating tuple with 3 items
print(mytuple)
mytuple = ( ) # creating an empty tuple
Creating Tuples print(mytuple)
mytuple = ( “apple”,) # creating a tuple with one item
print(mytuple)
• Using tuple( ) function
mytuple = tuple((“apple”, “banana”, “cherry”))
print(mytuple)
• Packing of Tuples
• assigning values to a tuple, when it is created is called packing
Ex : fruits = (“apple”, “banana”, “cherry”)
• Unpacking of Tuples
• extracting values from a tuple, back into variables is called unpacking
Ex : fruits = (“apple”, “banana”, “cherry”)
(green, yellow, red) = fruits
print(green)
print(yellow)
print(red)
• Deleting a tuple
Ex : fruits = (“apple”, “banana”, “cherry”)
del fruits
print(fruits) # error is generated, fruits not defined
Sample programs