PCAP 31 03 PCAP Certified Associate Python Programmer · Free Practice Question Easy

Question 37

Q466 - Operators


The expression:

'mike' > 'Mike'

is


  • A

    erroneous

  • B

    false

  • C

    true

Reveal correct answer

Correct answer: C

Explanation

Topic: greater than operator string comparison


Try it yourself:

Explanation:

The ASCII code of m is greater than the ASCII code of M


Q466 (Please refer to this number, if you want to write me about this question.)

A. In Python, string comparison is not erroneous. The comparison between 'mike' and 'Mike' is valid and evaluates to true because the lowercase 'm' has a higher Unicode value than the uppercase 'M'.

B. The comparison between 'mike' and 'Mike' is based on the Unicode values of the characters in the strings. Since the lowercase 'm' has a higher Unicode value than the uppercase 'M', the expression 'mike' > 'Mike' is true in Python.

C. In Python, string comparison is case-sensitive. Therefore, when comparing the strings 'mike' and 'Mike', the lowercase 'm' in 'mike' has a higher Unicode value than the uppercase 'M' in 'Mike'. As a result, the expression 'mike' > 'Mike' evaluates to true.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need