Datasheet

Chapter 1: A Python Primer
6
Operators
If you have programmed in other languages, the operators in Python will be familiar to you. The Python
operators are fundamentally similar to those used in other languages. In the code shown earlier, the
conditions evaluated in both
if statements involve comparison operators. The following table describes
the operators most commonly used in Python, and the ones used in this book:
Operator Symbol Example
Numeric Operators
Addition + x + y
Subtraction
x y
Multiplication * x * y
Division / x / y
Exponent (Power) ** x ** y (x to the y power)
Modulo % x % y (the remainder of x/y)
Comparison Operators
Greater than > x > y (x is greater than y)
Less than < x < y (x is less than y)
Equal to == x == y (x equals y)
Greater than or equal to > = x > = y (x is greater than or equal to y)
Less than or equal to < = x < = y (x is less than or equal to y)
Not equal to != or < > x != y, x < > y (x does not equal y)
Boolean Operators
and and x and y (if both are true, then the expression is true)
or or x or y (if either is true, then the expression is true)
not not not x (if x is false, then the expression is true)
Assignment Operator
Assignment = X = 15
name = “ Jim ”
c01.indd 6c01.indd 6 6/2/08 12:03:09 PM6/2/08 12:03:09 PM