Practice mode Python

Which list method removes the first item equal to a given value?

Correct answer A. remove()

Explanation

list.remove(x) deletes the first item whose value equals x and raises ValueError if there is none. pop() removes an item by index, defaulting to the last item, and returns it. discard() belongs to sets, and lists have no delete() method, although the del statement can remove items by index.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.