[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Quick question from newbie
On Wed, Oct 31, 2007 at 10:04:55PM -0400, Jonah Fishel wrote:
> If I had this:
>
> def print_i(i):
> if i == range(1, 9):
> print "It worked!"
> else:
> print "Bummer!"
>
> print_i(6)
>
> Why would I get Bummer! every time? Am I misusing range()?
No, you are not misusing range() you are misusing ==
== is for checking if two things are equal. To check if a value is in a
list, use the "in" operator, like this:
def print_i(i):
if i in range(1, 9):
print "It worked!"
else:
print "Bummer!"
---
James Paige