To add a new element to a list we use which Python command?
A. list1.addEnd(5)
B. list1.addLast(5)
C. list1.append(5)
D. list1.add(5)
Answer: Option C
Solution (By Examveda Team)
In Python, to add a new element to the end of a list, theappend()
method is used.The syntax for using
append()
is list_name.append(element)
, where list_name
is the name of the list and element
is the value to be added.append()
adds the specified element to the end of the list, increasing the list's length by one.Therefore,
list1.append(5)
will add the element 5
to the end of list1
.
Join The Discussion