Python Operators - Boolean is Not a Type of Broth
(Page 4 of 5 )
Boolean operators let us test if a value or more than one value is true. The AND operator says if this AND that are true, do this. The OR says if this OR that is true, do this. And Not is for inverse values.
Let's apply these to our majestic beer program:
#!/usr/local/bin/python
beers = 0
timmy = 20
tommy = 20
drunk = timmy+tommy
if beers == 0 and drunk < 100:
print "Did you guys drop a beer or something?"
elif beers <20 or drunk >80:
print "There aren't enough beers here to make you look good. Fortunately for you I am desparate."
else:
print "Glug glug glug"
Bitwise and Shift
We are going to skip the Bitwise and Shift functions for now, as those are mainly for low-level programming, and mostly what we will be learning is high-level programming. For now, just know that they exist on a plane far cooler than the one you do.
Next: Assignment Operators >>
More Python Articles
More By James Payne