+ 1

How to compare strings ?

print("a" < "b") print("a" < "a ") print(" " < "1") They’re all true. Why ?

12th Nov 2017, 11:05 PM
༺Bluxtyd༻
༺Bluxtyd༻ - avatar
5 Answers
+ 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.
12th Nov 2017, 11:44 PM
ChaoticDawg
ChaoticDawg - avatar
+ 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.
12th Nov 2017, 11:20 PM
ChaoticDawg
ChaoticDawg - avatar
0
Well, but print("b" < "a") is false.. Edit: btw, print(0 < 0) is false too
12th Nov 2017, 11:12 PM
༺Bluxtyd༻
༺Bluxtyd༻ - avatar
0
Thank you! Sorry for not including the language. It’s my first post and I didn’t know it 😄.
12th Nov 2017, 11:25 PM
༺Bluxtyd༻
༺Bluxtyd༻ - avatar
0
It’s because of the space after the a.
12th Nov 2017, 11:31 PM
༺Bluxtyd༻
༺Bluxtyd༻ - avatar