Python Python Basics Types and Branching Comparing values

Routine Poutine
Routine Poutine
24,081 Points

How is "python" > "chocolate" alphabetically? I am thinking "p" comes after "c," so I do not understand this.

How does alphabetical order put python before chocolate? I forgot this part of the material.

2 Answers

Steven Parker
Steven Parker
171,373 Points

You're right, "p" comes after "c", and that's why "python" > "chocolate".

Think about how it would be with numbers — 8 comes after 3, so 8 > 3.

Make sense now?

Chris Freeman
Chris Freeman
Treehouse Moderator 56,649 Points

To see it in code:

>>> ord('p')
112
>>> ord('c')
99
>>> ord('p') > ord('c')
True
Steven Parker
Steven Parker
171,373 Points

or just ... and:

>>> 'p' > 'c'                                                                                                               
True                                                                                                                        
>>> 'python' > 'chocolate'                                                                                                  
True                                                                                                                        
>>> 8 > 3                                                                                                                   
True  
Chris Freeman
Chris Freeman
Treehouse Moderator 56,649 Points

Also, true. The point of the ord() is to show how python determines the actual ordering. Python uses the ord() values underneath under the hood.

Steven Parker
Steven Parker
171,373 Points

Good illustration .. I guess I should have said "and" instead of "or".

Routine Poutine
Routine Poutine
24,081 Points

Thanks so much. I completely overlooked that logic.

Routine Poutine
Routine Poutine
24,081 Points

If ord("a") is 97, what comes before the alphabet? Is 96 a symbol?

Chris Freeman
Chris Freeman
Treehouse Moderator 56,649 Points

It appears to be grave accent

>>> ord('a')
97
>>> chr(97)
a
>>> chr(96)
‘`’
>>>