By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,520 Members | 1,766 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,520 IT Pros & Developers. It's quick & easy.

Re: compare items in list to x

P: n/a
2 is not equal to '2'
Nov 2 '08 #1
Share this Question
Share on Google+
1 Reply

P: n/a
On Nov 2, 9:54*pm, "Pete Kirkham" <mach....@gmail.comwrote:
2 is not equal to '2'
As the error is correctly marked, u have to convert '2' to 2 by using
int() function

so the write code is

x = 2

def compare():
for y in ['12', '33', '2']:
y=int(y) #string '2' is converted to int 2
if x < y:
print x, "is less than", y
elif x y:
print x, "is greater than", y
print x, "and", y, "are equal"


Asit Dhal
Nov 2 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.