Write the Python statement for each of the following tasks using BUILTIN functions/methods only:

(i) To remove the last element from the list L2 and store it in a variable x.

Answer:

Answer by student

The Python statement to  remove the last element from the list L2 and store it in a variable x is:

x = L2.pop() 

Detailed answer by teachoo

-lock-

  • To remove the last element from the list L2 and store it in a variable x, we can use the pop() method of the list object.
  • The pop() method takes an optional index as an argument and removes and returns the element at that index from the list.
  • If no index is given, it removes and returns the last element of the list.
  • Therefore, we can write x = L2.pop() to remove the last element from L2 and store it in x.

So, the correct answer is x = L2.pop() 

-endlock-

Remove Ads
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh is an IIT Kanpur graduate and has been teaching for 16+ years. At Teachoo, he breaks down Maths, Science and Computer Science into simple steps so students understand concepts deeply and score with confidence.

Many students prefer Teachoo Black for a smooth, ad-free learning experience.