Question-115: What would happen/print, when you run below program
listOfNames=['Amit' , 'John' , 'Venkat' , 'Simon' ]
del listOfNames[2]
listOfNames[3]='Amit'
print(listOfNames)
- ['Amit' , 'John' , 'Venkat' , 'Simon' ]
- Get all Questions and Answer from here
- You need to have paid subscription to access all questions
- 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. |