Question-115: What would happen/print, when you run below program

listOfNames=['Amit' , 'John' , 'Venkat' , 'Simon' ]

del listOfNames[2]

listOfNames[3]='Amit'

print(listOfNames)

 

  1. ['Amit' , 'John' , 'Venkat' , 'Simon' ]
  2. Get all Questions and Answer from here
  3. You need to have paid subscription to access all questions
  4. Thanks for considering Python Certification Material

 

Answer: E

Exp:  Since, you deleted 3rd element from a list using below line

del listOfNames[2]

Now list size is =3. Hence, when you are trying to add/update element at position, which does not exists.

listOfNames[3]='Amit'

Program will give error.

 

Deleting an element from a list

  • You can delete one element from a list using del
  • You can not directly assign element to a position, which currently does not exits in the list.

listOfNames=['Amit' , 'John' , 'Venkat' , 'Simon' ]

print("List Length ", len(listOfNames))

 

You can access to full explanation to question and answer from this page.

Why Dont you prepare for Python Certifications and Interview Questions with 250+ Questions and Answer : Check Here

Real Exam Number of Questions: 70 Questions
Real Exam Pass Score: 70%
Time Allotted: 90 minutes to complete exam