Bird
0
0

What will be the output of this code?

medium📝 Predict Output Q5 of 15
Python - Data Types as Values
What will be the output of this code?
text = 'Hello World'
print(text.strip())
AError
B'HelloWorld'
C' Hello World '
D'Hello World'
Step-by-Step Solution
Solution:
  1. Step 1: Understand the strip() method

    strip() removes leading and trailing whitespace from a string.
  2. Step 2: Analyze the string 'Hello World'

    There are no spaces at the start or end, so strip() returns the string unchanged.
  3. Final Answer:

    'Hello World' -> Option D
  4. Quick Check:

    strip() removes only outside spaces [OK]
Quick Trick: strip() removes spaces only at string ends [OK]
Common Mistakes:
MISTAKES
  • Expecting spaces removed inside string
  • Thinking strip() removes all spaces
  • Confusing strip() with replace()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes