very rare python expression

Tim Golden mail at timgolden.me.uk
Tue Aug 12 11:19:23 CEST 2008


甜瓜 wrote:
> Howdy everyone,
> 
> I saw a strange python code in pygame project. What does "while
> not(x&528or x in l):" mean? Below code works in python2.5, so "x&528"
> is not HTML strings.

Well I can't say I'd format it that way myself,
but it is valid. More conventionally laid out
the expression looks like this:

x & 528 or x in l

meaning:

if x & 528:
   return True
elif x in l:
   return True
else:
   return False

where x & 528 is the bitwise combination of x with 528.

Obviously the code you quote is taking the logical inverse
of this expression - "while not (...)"

TJG




More information about the Python-list mailing list