Bird
0
0

Why does iterating over a string in Python not allow modifying the string characters directly?

hard📝 Conceptual Q10 of 15
Python - For Loop
Why does iterating over a string in Python not allow modifying the string characters directly?
AIteration only works on lists, not strings
BPython forbids loops from changing any data
CStrings are immutable, so characters cannot be changed
DCharacters are copied, so changes don't affect original
Step-by-Step Solution
Solution:
  1. Step 1: Understand string immutability

    Strings in Python cannot be changed after creation; they are immutable.
  2. Step 2: Effect on iteration

    When iterating, you get characters but cannot assign new values to string positions.
  3. Final Answer:

    Strings are immutable, so characters cannot be changed -> Option C
  4. Quick Check:

    Strings immutable = no direct modification [OK]
Quick Trick: Strings cannot be changed after creation [OK]
Common Mistakes:
MISTAKES
  • Thinking iteration forbids all data changes
  • Believing strings are mutable like lists
  • Assuming characters are copied and modifiable

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes