Python Python Basics Types and Branching Comparing values

Lerena Holloway
Lerena Holloway
9,284 Points

>>> "python" > "chocolate" this would print out as True, but I don't understand how alphabetically works

in the syntax

"python" > "chocolate"

this would print out as True, but I don't understand how alphabetically this works. I'm confused by the terminology.

3 Answers

Elias Flores
Elias Flores
904 Points

I had this question too and after some research, this is what I've found:

Python is comparing the ASCII decimal(Dec) value of the first characters ("p" and "c" respectively) of the string. You can look at the table of the ASCII characters here: https://www.asciitable.com/

"p" has a Dec value of 112 while "c" has a Dec value of 99, and as you can guest 112 > 99 returns True

Lerena Holloway
Lerena Holloway
9,284 Points

Ahhh ok, that makes more sense . Thank so much!!!

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

P comes after C in the alphabet...picture the letters laid out left to right in order.