Python Tuple Set Practical
Python Tuple Set Practical
Aim:
a) Create Tuple
b) Access Tuple
c) Update Tuple
d) Delete Tuple
Theory:
Tuples are defined by parentheses () and can hold mixed data types.
- Update Tuple: Tuples are immutable. But we can convert it to a list, update it, and convert back to
a tuple.
- Delete Tuple: Use del to delete the entire tuple from memory.
Program:
# a) Create Tuple
# c) Update Tuple
temp_list = list(my_tuple)
temp_list[2] = 99
my_tuple = tuple(temp_list)
# d) Delete Tuple
del my_tuple
print("Tuple deleted.")
Output:
First element: 10
Last element: 50
Tuple deleted.
Conclusion:
Thus, the Python program successfully demonstrated creation, accessing, updating (via
Aim:
a) Create Set
c) Update Set
d) Delete Set
Theory:
Sets are mutable and defined using curly braces {} or the set() constructor.
- Access Elements: You can loop through the set using a for loop (direct indexing is not possible).
- Update Set: Use methods like add(), update() to modify the set.
- Delete Set: Use remove(), discard(), or clear() to delete elements or del to delete the entire set.
Program:
# a) Create Set
print("Accessing elements:")
print(item)
# c) Update Set
# d) Delete Set
print("Set deleted.")
Output:
Accessing elements:
100
200
300
Set deleted.
Conclusion:
Thus, the Python program successfully demonstrated how to create, access, update, and delete
elements in a set.