-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprac6.py
More file actions
33 lines (27 loc) · 1.06 KB
/
Copy pathprac6.py
File metadata and controls
33 lines (27 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#practical 6
print (" ******** Madanraj SAGAR *******")
# 1. Create a list
my_list = ["apple", "banana", "cherry"]
print("My list:", my_list)
# 2. Access list items
print("First item:", my_list[0]) # Accessing the first item (index 0)
print("Second item:", my_list[1]) # Accessing the second item (index 1)
print("Third item:", my_list[2]) # Accessing the third item (index 2)
# 3. Update list
# Add an item
my_list.append("orange") # add orange to the end of the list
print("List after adding orange:", my_list)
# Insert an item at a specific position
my_list.insert(1, "grape") # add grape at index 1
print("List after inserting grape:", my_list)
# Remove an item
my_list.remove("banana") # remove banana from the list
print("List after removing banana:", my_list)
# Remove an item by index
del my_list[0] # remove item at index 0
print("List after removing item at index 0:", my_list)
# 4. Delete the list
del my_list
# If you try to print my_list now, it will give an error because it's deleted.
# print(my_list) # this line will give an error.
print("List is now deleted.")