1)Write a Python program to create an empty list.
Then, add the following elements to the
list: 15, 25, 35, and 45. Finally, print the list.
Python Code:
my_list = []
my_list.extend([15, 25, 35, 45])
print(my_list)
2)Create two lists: list1 = [10, 20, 30] and list2 = [40, 50, 60]. Write a Python program to
join both lists and print the result.
Python Code:
list1 = [10, 20, 30]
list2 = [40, 50, 60]
joined_list = list1 + list2
print(joined_list)
3)Write a Python program that takes a list of numbers: [12, 5, 7, 3, 9, 1] and sorts it in
ascending order. Print the sorted list.
Python Code:
numbers = [12, 5, 7, 3, 9, 1]
numbers.sort()
print(numbers)
4)Given the list my_list = [100, 200, 300, 400, 500], write a Python program to remove the
number 300 from the list. Then print the updated list.
Python Code:
my_list = [100, 200, 300, 400, 500]
my_list.remove(300)
print(my_list)
5)Write a Python program that takes the list [1, 2, 4, 5] and inserts the number 3 between 2
and 4. Print the updated list.
Python Code:
my_list = [1, 2, 4, 5]
my_list.insert(2, 3)
print(my_list)
6)Given a list fruits = ['apple', 'banana', 'cherry'], write a Python program to create a copy of
this list and print the copied list.
Python Code:
fruits = ['apple', 'banana', 'cherry']
copied_fruits = fruits.copy()
print(copied_fruits)
7)Write a Python program to clear the entire list numbers = [5, 10, 15, 20] so that it
becomes empty. Print the list after clearing it.
Python Code:
numbers = [5, 10, 15, 20]
numbers.clear()
print(numbers)
8)Write a Python program to find and print the length of the list colors = ['red', 'green',
'blue', 'yellow'].
Python Code:
colors = ['red', 'green', 'blue', 'yellow']
print(len(colors))
9)Write a Python program to concatenate two lists a = [1, 2, 3] and b = [4, 5, 6] using a loop.
Print the final concatenated list.
Python Code:
a = [1, 2, 3]
b = [4, 5, 6]
concatenated_list = []
for item in a:
concatenated_list.append(item)
for item in b:
concatenated_list.append(item)
print(concatenated_list)
10)Given the list grades = [85, 90, 78, 92, 88], write a Python program to sort the list in
descending order and print the result.
Python Code:
grades = [85, 90, 78, 92, 88]
grades.sort(reverse=True)
print(grades)