Home arrow Python arrow Page 4 - Python Operators

Boolean is Not a Type of Broth - Python

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.

TABLE OF CONTENTS:
  1. Python Operators
  2. The Prestigious Mathematical Operators
  3. The Judgmental Comparison Operators
  4. Boolean is Not a Type of Broth
  5. Assignment Operators
By: James Payne
Rating: starstarstarstarstar / 8
January 14, 2008

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

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.



 
 
>>> More Python Articles          >>> More By James Payne
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PYTHON ARTICLES

- Python Big Data Company Gets DARPA Funding
- Python 32 Now Available
- Final Alpha for Python 3.2 is Released
- Python 3.1: String Formatting
- Python 3.1: Strings and Quotes
- Python 3.1: Programming Basics and Strings
- Tuples and Other Python Object Types
- The Dictionary Python Object Type
- String and List Python Object Types
- Introducing Python Object Types
- Mobile Programming using PyS60: Advanced UI ...
- Nested Functions in Python
- Python Parameters, Functions and Arguments
- Python Statements and Functions
- Statements and Iterators in Python

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: