+ 1
How to compare strings ?
print("a" < "b") print("a" < "a ") print(" " < "1") They’re all true. Why ?
5 odpowiedzi
+ 4
@IEditit Ruby string comparisons work in a similar way to Python's I think they call it ASCIIbetical, but the result would be the same as those posted.
+ 3
You didn't include what language this question is for. I'm going to assume that it's python, since that's what it looks like.
Python does string comparisons lexicogrphically using the ASCII values of the characters in order.
http://thepythonguru.com/python-strings/
scroll down to the string comparison section.
0
Well, but print("b" < "a") is false..
Edit: btw, print(0 < 0) is false too
0
Thank you! Sorry for not including the language.
It’s my first post and I didn’t know it 😄.
0
It’s because of the space after the a.