i
: the position where the element is to be addedx
: the element to be added my_list=['Alex','Ronald','John']
my_list.insert(1,'Ravi')
print(my_list)
Output is here
['Alex', 'Ravi', 'Ronald', 'John']
my_list=['Alex','Ronald','John']
#my_list.append('new name') # adds at the end of the list
my_list.insert(len(my_list),'new name') # adds at the end of the list
print(my_list)
my_list=[1,5,2,3]
my_list.insert(2,22)
print(my_list)
Output
[1, 5, 22, 2, 3]
Using len() to check the length of the list
my_list=['Alex','Ronald','John']
print("Length before append : ",len(my_list))
my_list.append('Ravi')
print("Length after append : ",len(my_list))
print(my_list)
Output is here
Length before append : 3
Length after append : 4
['Alex', 'Ronald', 'John', 'Ravi']
All list methods
Questions with solutions on ListAuthor
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.