Bird
0
0

What does the function random.choice(list) do in Python?

easy📝 Conceptual Q2 of 15
Python - Standard Library Usage
What does the function random.choice(list) do in Python?
ASelects a random element from the list
BSorts the list randomly
CRemoves a random element from the list
DReturns the length of the list
Step-by-Step Solution
Solution:
  1. Step 1: Understand random.choice

    random.choice(list) picks one random item from the list.
  2. Step 2: Check other options

    It does not sort, remove, or count elements.
  3. Final Answer:

    Selects a random element from the list -> Option A
  4. Quick Check:

    random.choice = select random element [OK]
Quick Trick: random.choice picks one item from a list [OK]
Common Mistakes:
  • Thinking it sorts the list
  • Assuming it removes an item
  • Confusing with len()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes