This Python Numbers lesson is for a beginner. Read the short notes, run each example, then change one name or number and run it again.
Integers have no decimal point. Floats do. Division with / always gives a float. // drops the fraction, and % is the remainder.
For money, integers of paise or the decimal module are safer than a binary float.
Example 1: Start here
** is power. 2 ** 4 is 16.
print(7 / 2) # the math runs, then print shows the result
print(7 // 2) # // keeps the whole number and drops the fraction
print(7 % 2) # % is the remainder
print(2 ** 4) # ** means to the power of
Example 2: Integer and float
A single slash always gives a float, so 20 / 4 is 5.0.
print(20 + 4) # the math runs, then print shows the result
print(20 / 4) # the math runs, then print shows the result
Example 3: Whole-number division
// drops the fraction. % is the remainder.
print(20 // 6) # // keeps the whole number and drops the fraction
print(20 % 6) # % is the remainder
Example 4: A power
** means power. 2 to the power of 3 is 8.
print(2 ** 3) # ** means to the power of
