nerdexam
Python_Institute

PCEP-30-02 · Question #90

What is the expected output of the following code? ``python print('Mike' > 'Mikey') ``

The correct answer is A. False. A is correct because Python compares strings lexicographically, character by character. 'Mike' and 'Mikey' share the same first four characters, but 'Mike' is shorter - and in Python, a string that is a prefix of another is always considered less than the longer one, making…

Question

What is the expected output of the following code?
print('Mike' > 'Mikey')

Options

  • AFalse
  • BTrue
  • C1
  • D0

How the community answered

(34 responses)
  • A
    71% (24)
  • B
    3% (1)
  • C
    18% (6)
  • D
    9% (3)

Explanation

A is correct because Python compares strings lexicographically, character by character. 'Mike' and 'Mikey' share the same first four characters, but 'Mike' is shorter - and in Python, a string that is a prefix of another is always considered less than the longer one, making 'Mike' > 'Mikey' evaluate to False.

B (True) is wrong because the relationship is actually the reverse: 'Mike' < 'Mikey', not greater than.

C (1) and D (0) are wrong because Python's > operator returns a boolean (True or False), not an integer - unlike some languages where comparisons return numeric values.

Memory tip: Think of dictionary order - if you looked up "Mike" and "Mikey" in a dictionary, "Mike" appears before "Mikey," meaning it comes first (is smaller). The word that appears earlier in the dictionary is always the lesser value in Python string comparison.

Community Discussion

No community discussion yet for this question.

Full PCEP-30-02 Practice