Python Integer Number
About Python Interger Number
In Python, an integer is a whole number without any decimal or fractional part. Integers can be positive (99), negative (-99), or zero (0).
In Python3, the size of the integer number is limited only by available memory.
Creating an Integer Number
You can define an integer number in Python by simply assigning a whole number to a variable.
In the following example, a whole positive number '99' is assigned to the variable 'num_positive' to create an integer variable.
type() function is used to get the type of the variable 'num_positive'.
In the same way, you can create negative integer number.
Example of Integer Number:
Output of the above example
<class 'int'>
<class 'int'>
For both positive and negative numbers, we get the class type 'int'. That refers that both are integer numbers.
Uses of Integer Numbers
Integer variables can be used in a wide range of programming tasks, from simple arithmetic tasks to more complex programming tasks.
Various mathematical operations such as addition, subtraction, multiplication, and division can be performed with integers in Python.
You need to use '+' operator for addition, '-' operator for subtraction, '*' operator multiplication, and '/' operator division.
In the following example, a = 10 and b = 3 integer variables are created. Different mathematical operations are performed using these variables.
Please observe the following examples:
Example of mathematical operations of integer numbers:
Output of the above example
13
7
30
3.3333333333333335
3
Please note that the return type of division of integer numbers is float type in Python 3. To get an integer type result, use '//' (double slash) in the division instead of '/' (single slash).
Python Compiler For Live Practice
Practice the above Python code in the following Python Editor. Create more Python interger number variables and perform mathematical and other operations in the following code editor and click Execute button. Output will be displayed in Python Code Output section.
Python Editor