Skip to content

Latest commit

 

History

History
19 lines (11 loc) · 886 Bytes

006-Floats.md

File metadata and controls

19 lines (11 loc) · 886 Bytes

Floats

What is a float in Python?

A float is a number that contains a decimal point somewhere. Floats are treated differently from whole numbers by Python, and give more exact answers when doing arithmatic.

When to use floats

I always say use a floating number when you need a precise answer, rather than one that has been rounded to the nearest whole number, and if you would specifically like a floating number to be in your output, then ensure there is at least one floating number in your input values. This is especially important when using python 2 version, however in Python 3 the output of two integers will provide a floating number unless you specify otherwise.

Example floating numbers

Here are two variables that have floating numbers assigned to them:

a_float = 5.46
pi = 3.1415
another_valid_float = 1.0
this_is_valid_too = 7.