Name

float

Examples
# Declare variable 'a' and assign it the value 1.5387
a = 1.5387 

# Declare variable 'b' and assign it the value -2.984
b = -2.984 

# Declare variable 'c' and assign it the sum of 'a' and 'b'
c = a + b  
f = 0
for i in range(100000):
    f = f + 0.0001  # Bad idea! See below.

for i in range(100000):
    # The variable 'f' will work better here,
    # less affected by rounding
    # Count by thousandths
    f = i / 1000.0  
Description Data type for floating-point numbers, a number that has a decimal point.
Floats are not precise, so avoid adding small values (such as 0.0001), as these may not always increment because of rounding error. If you want to increment a value in small intervals, use an int, and divide by a float value before using it. (See above example.)

Syntax
var = value
Parameters
varvariable name referencing the float
valueany floating-point value
Related int
Updated on Tue Jul 11 06:52:23 2017.
Creative Commons License