+ 1

When I tried the following code in pc, it gives an output as 'False', 'False' and 'True' respectively. Why?

The symbol "<,>" acts as "!=" in case of strings. https://code.sololearn.com/cQ0S9lDlqy55/?ref=app

6th Jan 2019, 9:10 AM
Ashutosh Dash
Ashutosh Dash - avatar
4 Respostas
+ 4
The strings are ordered alphabetically (like in a dictionary). 'j' comes before 'p', so 'jet' is treated as smaller than 'plane'. 'halo' is neither greater nor less than itself, just as in the case of numbers.
6th Jan 2019, 9:17 AM
Kishalaya Saha
Kishalaya Saha - avatar
+ 5
> The symbol "<,>" acts as "!=" in case of strings. Just want to add that that isn't true. Like Kishalaya Saha explained, strings are compared lexicographically which means that the string 'aaa' is 'smaller' than the string 'zzz' because if you sort them alphabetically, 'aaa' will come before 'zzz'. So 'aaa' < 'zzz' is True and 'zzz' < 'aaa' is False. https://en.wikipedia.org/wiki/Lexicographical_order
6th Jan 2019, 10:29 AM
Anna
Anna - avatar
+ 1
Thanks Anna! 😊 Ashutosh Dash First the first characters will be compared. When they are the same, the second characters will be compared, and so on... So "abc" < "acb", as their first characters are the same, but the second one in the second string comes after the second one in the first string. Just like in a dictionary, where "jet" comes before "plane".
6th Jan 2019, 12:21 PM
Kishalaya Saha
Kishalaya Saha - avatar
0
Kishalaya Saha why in a string consisting of group of alphabetical characters, the first character will be given priority?
6th Jan 2019, 9:33 AM
Ashutosh Dash
Ashutosh Dash - avatar