Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Basics Types and Branching Comparing values

Routine Poutine
Routine Poutine
26,050 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
229,708 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 68,423 Points

To see it in code:

>>> ord('p')
112
>>> ord('c')
99
>>> ord('p') > ord('c')
True
Steven Parker
Steven Parker
229,708 Points

or just ... and:

>>> 'p' > 'c'                                                                                                               
True                                                                                                                        
>>> 'python' > 'chocolate'                                                                                                  
True                                                                                                                        
>>> 8 > 3                                                                                                                   
True  
Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 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
229,708 Points

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

Routine Poutine
Routine Poutine
26,050 Points

Thanks so much. I completely overlooked that logic.

Routine Poutine
Routine Poutine
26,050 Points

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

Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

It appears to be grave accent

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