how in boolean "banjoi" < "sanjo" returns true? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

how in boolean "banjoi" < "sanjo" returns true?

banjoi has 6 letters while sanjo has only 5

29th Aug 2016, 10:19 AM
ankur pancholi
ankur pancholi - avatar
7 Answers
+ 6
It compares the ASCII code of the first character(letter) in words b=98 s=115 So s>b So it returns True If the first character is the same , it compares second character(and so on) so 'su'<'sv' You can get the ASCII code of a letter using ord() eg: ord("a") would give 97 And the letter associated with ASCII code can be retrieved using chr() eg: chr(100) would give "c" capital letters come before simple letters in ASCII table so "S"<"s" ASCII table is available in http://www.asciitable.com/ or Google it 😀
11th Oct 2016, 1:53 PM
Sunera
Sunera - avatar
+ 5
it's because 'b' comes bevore 's'
29th Aug 2016, 10:36 AM
Anton Baumann
Anton Baumann - avatar
+ 1
alphabetically, "banjoi" comes before "sanjo" therefore it is the lesser of the two.
30th Aug 2016, 6:05 AM
Cornel
Cornel - avatar
+ 1
great explanations thanks guys
16th Sep 2016, 4:31 PM
daillman
daillman - avatar
0
if u want compare lenghts: len("banjoi")<len("sanjo")
29th Aug 2016, 12:40 PM
Pavel
0
run by dictionary
30th Aug 2016, 6:18 PM
beauty1234
- 1
сложнаа
20th Sep 2016, 9:26 AM
Иван
Иван - avatar