In the previous two articles on Python, I promised to tell you about Operators, but I lied. Instead I covered such things as conditionals, sets, lists, dictionaries, and so forth. Now, at last, I am going to cover the various operators that Python has to offer, and force you, I mean teach you, to manipulate data with them.
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.