PCEP-30-02 · Question #50
What is the expected output of the following code? data = 'Hello@Peter!!' print(data.lower())
The correct answer is C. hello@peter!! str.lower() converts only alphabetic characters to lowercase, leaving all non-letter characters - including @, !, digits, and spaces - completely unchanged. Since 'Hello@Peter!!' contains letters (H, e, l, l, o, P, e, t, e, r) plus the symbols @ and !!, the method lowercases…
Question
Options
- Ahellopeter
- Bhello@Peter!!
- Chello@peter!!
- DNone
How the community answered
(46 responses)- A11% (5)
- B7% (3)
- C80% (37)
- D2% (1)
Explanation
str.lower() converts only alphabetic characters to lowercase, leaving all non-letter characters - including @, !, digits, and spaces - completely unchanged. Since 'Hello@Peter!!' contains letters (H, e, l, l, o, P, e, t, e, r) plus the symbols @ and !!, the method lowercases only the letters, producing 'hello@peter!!', which is C.
- A (
hellopeter) is wrong because it strips the@and!!-.lower()never removes characters. - B (
hello@Peter!!) is wrong becauseP,e,t,e,rare still mixed-case;.lower()affects all letters, not just the first word. - D (
None) is wrong because.lower()returns a new string - it only returnsNoneif it were an in-place operation with no return value, which isn't the case here.
Memory tip: Think of .lower() as a filter that only "sees" letters - everything else (punctuation, symbols, numbers) passes through invisible and untouched.
Community Discussion
No community discussion yet for this question.