Resources
The other type of number we can store in Python is a floating-point number. We won’t go into too much detail about floating-point values here, since you’ll learn about them elsewhere in this class. For the purposes of programming, the only thing to know about floating-point numbers is that they are used to represent numbers that include a fractional or decimal portion. In Python, these values are stored in the float
data type.
To create a variable that stores a floating-point value in Python, we can use an assignment statement that includes a value with a decimal point, like this:
a = 5.8
We can also create negative values using the negative symbol -
:
b = -7.987
Finally, it is possible to store a whole number in a floating-point value by simply adding a decimal point and a 0
at the end of the value, as in this example:
c = 42.0
Later in this lab, we’ll see a couple of situations where that may be useful.
For now, we’re just going to assume that Python can easily handle any reasonable number we want it to store in a float
variable, but there are some limits to the size and accuracy of those numbers. To reach these limits, we usually have to be dealing with numbers that have