print("java">"javascript") in python prints false | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

print("java">"javascript") in python prints false

can u explain me why does this happen on what basis does it compare words

8th May 2018, 8:20 AM
Suhail Ahmad
Suhail Ahmad - avatar
2 Answers
+ 10
It's true that Java < Javascript. Lol...Jk... ^^ Jokes aside, Python compares strings on the basis of their ASCII values. Hence, when the code - python ("java" > "javascript") executes.... The compiler checks every letter. First it checks "j" , as both the sides have "j" it jumps to the second letter .. The second is also same , so as the third and fourth too....The fifth letter doesn't exist in the word "java" but it does in "javascript". Hence it evaluates that to false. Some more examples print("b" > "a") => True print("A" > "a") => False
8th May 2018, 8:56 AM
Nikhil
Nikhil - avatar
+ 1
thanks man
8th May 2018, 9:06 AM
Suhail Ahmad
Suhail Ahmad - avatar