0

I'm using Python 3.4, wondering why Python allowing these codes;

>>> "a">"b"
False
>>> "a"<"b"
True
>>> 

I think it's maybe about their order in ASCII but I will appriciated if someone explain why Python allows like this things. The weird part is, if it was in Python 2x I could understand that but, it's Python 3x. Shouldn't Python throw an SyntaxError?

Edit: I tried non-Ascii character;

>>> "ç">"a"
True
>>> 

And it's not about ASCII then I understand that, so why Python allowing this?

2 Answers2

3

Here's a link that describes your question

The standard comparisons (<, <=, >, >=, ==, !=) apply to strings. These comparisons use the standard character-by-character comparison rules for ASCII or Unicode.

EDIT:

See this other stack overflow post and also look up the ord() function

String Comparison Technique Used by Python

Edit!! ord() doesn't work here as 'ç' is not a single byte character

Community
  • 1
  • 1
Maxwell Grady
  • 306
  • 4
  • 12
  • @PadraicCunningham True, I take back this as correct answer –  Jan 10 '15 at 00:46
  • @importV, the character by character assessment still holds true, it would make sense that any character like "ç" should be greater than any character like ascii characters that can be stored in a single byte – Padraic Cunningham Jan 10 '15 at 00:56
  • Padraic - I should have tested that myself before hand - you are correct in ord() not working. – Maxwell Grady Jan 10 '15 at 01:09
0

Sorting names in friend list, sorting search results, searching for best match. Comparing string is among the most needed operations.

Andrew_Lvov
  • 4,621
  • 2
  • 25
  • 31