Python Integers and Floats

Integers and Floats

Python has two different basic data types for representing numbers- the integer and the float. Integers are used to represent whole numbers, while the float (or floating point number) is use to represent a number with a decimal. We can use the assignment operator to create an integer or a float.

 new_int = 12 # 12 is an integer, a whole number
new_float = 12.1 # 12.1 is a float, it contains a decimal

We can also create an integer or a float from another object using Python's built-in `int` or `float` functions.

 int_from_string = int("12") # convert a string to int
float_from_string = floatt("12.1") # convert a string to float