Bird
Raised Fist0

What is the output of this code?

medium📝 Predict Output Q13 of Q15
Python - Standard Library Usage
What is the output of this code?
import random
items = ['apple', 'banana', 'cherry']
random.shuffle(items)
print(items)
ASyntaxError because shuffle returns a new list
B['apple', 'banana', 'cherry'] (always same order)
CA new list with one random item from items
DA randomly shuffled list of the original items
Step-by-Step Solution
Solution:
  1. Step 1: Understand random.shuffle behavior

    random.shuffle rearranges the list elements in place randomly. It does not return a new list.
  2. Step 2: Analyze the print output

    After shuffling, printing items shows the same list but with elements in random order. So output is a shuffled list, not the original order or a single item.
  3. Final Answer:

    A randomly shuffled list of the original items -> Option D
  4. Quick Check:

    shuffle changes list order in place [OK]
Quick Trick: shuffle changes list order in place, no new list returned [OK]
Common Mistakes:
MISTAKES
  • Expecting shuffle to return a new list
  • Thinking shuffle picks one random item
  • Assuming list order stays same

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes