December 2000
Intermediate to advanced
816 pages
16h 57m
English
The standard mathematical operators that you are familiar with work the same way in Python as in most other languages.
+ - * / % **
Addition, subtraction, multiplication, division, and modulus/remainder are all part of the standard set of operators. In addition, Python provides an exponentiation operator, the double star/asterisk ( ** ). Although we are emphasizing the mathematical nature of these operators, please note that some of these operators are overloaded for use with other data types as well, for example, strings and lists.
>>> print -2 * 4 + 3 ** 2
1
As you can see from above, all operator priorities are what you expect: + and - at the bottom, followed by *, /, and %, then comes the unary + and -, and finally,
Read now
Unlock full access