+ 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
4 Antworten
+ 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.
+ 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
+ 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".
0
Kishalaya Saha why in a string consisting of group of alphabetical characters, the first character will be given priority?