Skip to content

Instantly share code, notes, and snippets.

@sshehrozali
Created November 16, 2020 13:33
Show Gist options
  • Save sshehrozali/72c15f762cb7e1bf196423f6e23b6d68 to your computer and use it in GitHub Desktop.
Save sshehrozali/72c15f762cb7e1bf196423f6e23b6d68 to your computer and use it in GitHub Desktop.
Python program to demonstrate the use of list.insert()
# Python program to demonstrate the use of list.insert() # Developed By Syed Shehroz Ali
# New List
my_list = ["Hello", "World", "Cat", "Dog"]
# Print List
print("\nList:", my_list)
# Print Total length of list
print("\nTotal Length of list: ", len(my_list), "\n")
print("Each word in list with index no")
# Print each word in List with index no
for i in range(len(my_list)):
print(i, ":", my_list[i])
# Insert new word in List at index no = 3
my_list.insert(3, "Mouse")
print("\nUpdated word in list with index no")
# Print each word in updated List with index no
for i in range(len(my_list)):
print(i, ":", my_list[i])
# Indicate the inserted word at index no = 3
if i == 3:
print(i, ":", my_list[i], " <- This is the inserted word")
# Print new line, end the program
print("\n")
exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment