0

Why the result of “bag” > “apple” is True in Python? I tried this code below i don't know why it show this result and how? Please some one explain it.

print("bag" > "apple")

True

1 Answers1

2

I believe this is True because Python compares the first letter of each word. And b is greater than a in Python.

Fiyin Akinsiku
  • 166
  • 2
  • 13
  • But point is how "b" is greater than "a"? – md daudul islam sumon Feb 23 '20 at 15:27
  • "b" comes after "a" in the alphabet (which is why the corresponding ASCII values have the same relationship). – Seb Feb 23 '20 at 15:28
  • print(ord("b")) -> 98 print(ord("a")) -> 97 for that reason b > a right? – md daudul islam sumon Feb 23 '20 at 15:29
  • Welcome to Stack Overflow. This question is definitely a duplicate; it's best to avoid answering, so that it's easier to close and then the original question is easier to find by searching. See https://stackoverflow.com/help/how-to-answer - *Not all questions can or should be answered here. Save yourself some frustration and avoid trying to answer questions which... ...have already been asked and answered many times before.* - By the way, your answer makes it sound like Python *only* compares the first letter of each word, which is not always true. – kaya3 Feb 23 '20 at 15:31