Python Lists and List Operations
10 Questions
1 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What does the list method insert(i,x) do?

  • Appends item x to list y
  • Inserts item x to list y at position i (correct)
  • Deletes item x from list y
  • Returns the number of times x appears in list y

What does the list method remove(x) do?

  • Removes the first item from list y that has a value of x (correct)
  • Inserts item x to list y at the front
  • Appends item x to list y
  • Deletes item x from list y

What does the del statement do in Python when used with a list?

  • Appends a new item to a list
  • Deletes an item in a list (correct)
  • Reverses the items in a list
  • Sorts the items in a list

What error is raised when trying to access an index out of bound in a list?

<p>IndexError: list index out of range (B)</p> Signup and view all the answers

What is the output of the code 'print('a b c'.split())'?

<p>[a, b, c] (D)</p> Signup and view all the answers

What does the expression len(['p', 's', 'y']) return?

<p>3 (D)</p> Signup and view all the answers

What does the code 2 * ['a'] produce?

<p>['a', 'a'] (C)</p> Signup and view all the answers

What does the method remove() do for a list?

<p>Removes the first occurrence of a specific value from the list (C)</p> Signup and view all the answers

Which function is used to find the number of elements in a list?

<p>len() (B)</p> Signup and view all the answers

What does the expression ['add', 'class', 'contains', 'delattr'] represent?

<p>List of available methods for a list object (D)</p> Signup and view all the answers

More Like This

Python Lists: Operations and Comprehensions
10 questions
Python Tuple and List Operations
10 questions
Python Tuples and Lists Quiz
10 questions
Python List Operations: Optimization
41 questions
Use Quizgecko on...
Browser
Browser