Write a Python program to clone or copy a list


This program demonstrates how to create a new list that is a copy of an existing list.

  • The first line of the program creates a list called "old_list" that contains the values 10, 22, 44, 23, and 4.
  • The second line of the program creates a new list called "new_list" using the built-in "list" function. The "list" function takes an iterable as an argument, in this case the "old_list" and returns a new list containing all the elements of the iterable.
  • Finally, the program prints out the values of both the old_list and new_list to show that they are identical. This means that the new_list is a copy of the old_list and any changes made to new_list will not affect the values of the old_list and vice-versa.

Source Code

old_list = [10, 22, 44, 23, 4]
new_list = list(old_list)
print("Old List : ",old_list)
print("New List : ",new_list)

Output

Old List :  [10, 22, 44, 23, 4]
New List :  [10, 22, 44, 23, 4]

Example Programs