nerdexam
Python_Institute

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

What is the expected output of the following code? data = 'Hello@Peter!!' print(data.lower())

Options

  • Ahellopeter
  • Bhello@Peter!!
  • Chello@peter!!
  • DNone

How the community answered

(46 responses)
  • A
    11% (5)
  • B
    7% (3)
  • C
    80% (37)
  • D
    2% (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 because P, e, t, e, r are still mixed-case; .lower() affects all letters, not just the first word.
  • D (None) is wrong because .lower() returns a new string - it only returns None if 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.

Full PCEP-30-02 Practice