Operators [June 19, 2011, 2:59 a.m.]
Operators work with one or more objects and can perform tasks such as math, comparison, and inspection.
Math
There are standard operators for arithmetic:
Operator | Description |
+ | Addition |
- | Subrtaction |
* | Multiplication |
/ | Division |
% | Modulus division |
** | Exponent |
Assignment
Additionally, you can modify a named value and assign the output of an operator to the name in one line with inline assignment operators.
>>> a_number = 1 >>> a_number += 1 >>> a_number 2 >>> a_number *= 8 >>> a_number 8 >>> a_number **= 2 >>> a_number 64 >>> a_number /= 2 >>> a_number 32 >>> a_number %= 3 >>> a_number 2
Further Reading
- Python Documentation: Operator