Why does 4 < '3' return True in Python 2?
Is it because when I place single quotes around a number Python sees it as a string and strings are bigger than numbers?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, any number will be less than any string (including the empty string) in Python 2.
In Python 3, you can’t make arbitrary comparisons. You’ll get a
TypeError.From the link in eryksun’s comment:
So at least in recent versions of CPython 2.x, type names are compared, with an empty string used instead of the type name for any numeric type.