Question-119: When you run below program, what would be printed
listOfNames=['Amit' , 'John' , 'Venkat' , 'Simon' ]
listOfNames.append('Venu')
listOfNames.append('Nikita')
listOfNames.append('Sunil')
listOfNames.append('Richa')
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
Abswer: B
Exp:
Appending elements in an existing (entity) list.
- We are having method called append, which is owned by List.
- Hence, to call/invoke this method, you can use list(entity) itself.
- When you call method, it changes the state of the list itself.
- In below example append() is a method and len() is a function.
- append method, will always append element at the end of the list.
listOfNames=['Amit' , 'John' , 'Venkat' , 'Simon' ] print("List Length ", len(listOfNames))
#listOfNames=listOfNames+['Venu'] listOfNames.append('Venu') #listOfNames=listOfNames+['Nikita'] You can access to full explanation to question and answer from this page. |