python tutorial

Python Number

Learn more about Python, one of the world’s most versatile and popular programming languages.

Another data type used to store values in a variable is called a python number.


Python Number Type

Number data types have two major categories in Python. A number that does not contain a decimal point value is considered an integer or int. This is the first category within the number data type. A numeric value with decimal precision is called float or a floating-point number. This is the second category. Let’s try to use some int and float data types. Type the following code line-by-line in your notebook:

operand_one = 30
operand_two = 7
result = operand_one / operand_two # 30 / 7 = 4.285714285714286
result
4.285714285714286
type(operand_one)
int
type(operand_two)
int
type(result)
float

As shown above, we stored the numbers 30 and 7 in two different variables operand_one and operand_two. We also stored the outcome of dividing operand_one by operand_two in a variable called result. Now, when we check the value stored in the result it turns out to be a value with decimal point precision in it.

In order to check the type of data stored in a given variable, we use a helper function (more on functions later) called: type(value or variable name). Within the brackets we need to add what we are looking to evaluate. Let’s examine how to use this. For example, if we want to check the type of data stored in a variable called operand_one, we will use this function as type(operand_one) and it will return the data type of the value stored in that variable. operand_one and operand_two are storing values of int type, and result is storing a value of float type.

Learn Python Today

Get hands-on experience writing code with interactive tutorials in our free online learning platform.

  • Free and fun
  • Designed for beginners
  • No downloads or setup required