+ 3
How is '120' greater than '1000' in string format?
5 Antworten
+ 1
Because strings are not numbers.
Take the individual numbers placement.
1 is the first number for each element they are both equal.
But 120 has a "2" as the second digit and 1000 has "0".
2 is higher than 0 so '120' is bigger.
Look at the other example
print('9' > '800')
O/p:- True
Since '9' is greater than '8'
Therefore it's output is True
Because both on their first place
They have different numbers
Since '9' is greater than '8'
Therefore it's output is True
+ 7
String comparation is according to ASCII of each character. You can get ASCII of a character using ord(). Because 2 > 0 in ASCII, thus '120' is greater than '1000'.
+ 4
FYI, Python 3 actually uses unicode (UTF-8) encoding by default, which is basically an 8 bit expanded version of the ascii table. String comparisons are done lexicographically in the manner that CarrieForle stated.
+ 1
According to ASCII code 120 is greater than 1000,it is due to string comparison occur in ASCII code.
+ 1
in string it is same because it's string, not number or double or integer
so in string that is same, sory i don't know ASCII