0% found this document useful (0 votes)
2 views3 pages

Python Programming Lab 2B

Uploaded by

bushrajangli9
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Python Programming Lab 2B

Uploaded by

bushrajangli9
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PYTHON PROGRAMMING (1BPLC105B) LAB COMPONENT

2. b. Write a python program to create a list and perform the following operations
• Inserting an element
• Removing an element
• Appending an element
• Displaying the length of the list
• Popping an element
• Clearing the list

Source Code:

# Creating a list

my_list = [10, 20, 30, 40, 50]

print("Original list:", my_list)

# Inserting an element

my_list.insert(2, 25) # Inserts 25 at index 2

print("After inserting 25 at index 2:", my_list)

# Removing an element

my_list.remove(40) # Removes the first occurrence of 40

print("After removing 40:", my_list)

# Appending an element

my_list.append(60) # Adds 60 at the end

print("After appending 60:", my_list)

# Displaying the length of the list

print("Length of the list:", len(my_list))


# Popping an element

popped_element = my_list.pop() # Removes the last element

print("Popped element:", popped_element)

print("After popping an element:", my_list)

# Clearing the list

my_list.clear() # Removes all elements

print("After clearing the list:", my_list)

Screenshot of Code:
OUTPUT:

You might also like