Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 14 Online
OpenStudy (anonymous):

what happens when comparing a string to an int? How python will evaluate the test? For instance '32'>62 is False or True Thank you

OpenStudy (e.mccormick):

It will throw an exception. >>> '32'>25 Traceback (most recent call last): File "<string>", line 301, in runcode File "<interactive input>", line 1, in <module> TypeError: unorderable types: str() > int() Easy enough to test that in IDLE, PyScripter, etc. In contrast: >>> '32'>str(25) True

OpenStudy (anonymous):

Thank you

OpenStudy (e.mccormick):

np. Have fun!

OpenStudy (anonymous):

hmm.... >>> 25 > '35' False >>> '35' > 25 True >>> Python 2.7.4 (default, Apr 6 2013, 19:54:46) [MSC v.1500 32 bit (Intel)] on win32

OpenStudy (e.mccormick):

Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:03:43) [MSC v.1600 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> 25 > '35' Traceback (most recent call last): File "<pyshell#0>", line 1, in <module> 25 > '35' TypeError: unorderable types: int() > str() >>> 2.6.5 also acts the way 2.7.4 did. So looks like it is one of those things they are tightening up in the typing system. Python is supposed to be strongly but dynamically typed. http://wiki.python.org/moin/Why%20is%20Python%20a%20dynamic%20language%20and%20also%20a%20strongly%20typed%20language

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!