The way Python handles numbers is more precise than some other languages. It has all the normal operators—such as `+`

for addition, `-`

for subtraction, `/`

for division, and `*`

for multiplication—but it adds `%`

for modulus (division remainder), `**`

for raise to the power, and `//`

for floor division. It is also specific about which type of number is being used, as this example shows:

>>> a = 5>>> b = 10>>> a * b50>>> a / b0>>> b = 10.0>>> a / b0.5>>> a // b0.0

The first division returns `0`

because both `a`

and `b`

are integers (whole numbers), so Python calculates the division as an integer, giving `0`

. By converting `b`

to `10.0`

, Python considers it to be a floating-point number, and so the division is now calculated as a floating-point value, giving

Start Free Trial

No credit card required