Bird
0
0

What does the following code do?

easy📝 Conceptual Q11 of 15
Python - For Loop
What does the following code do?
for letter in "hello":
print(letter)
APrints each letter of the word 'hello' on a new line
BPrints the whole word 'hello' once
CPrints the length of the word 'hello'
DCauses an error because strings can't be looped
Step-by-Step Solution
Solution:
  1. Step 1: Understand the for loop over a string

    The loop goes through each character in the string "hello" one by one.
  2. Step 2: Print each character

    Inside the loop, each letter is printed on its own line.
  3. Final Answer:

    Prints each letter of the word 'hello' on a new line -> Option A
  4. Quick Check:

    Loop over string prints letters individually [OK]
Quick Trick: For loops over strings print letters one by one [OK]
Common Mistakes:
MISTAKES
  • Thinking the whole string prints at once
  • Confusing string length with letters
  • Believing strings can't be looped

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes