An integer is a whole number with no decimal point. In Python, integers can be positive, negative, or zero. You can use an integer directly in your code or store it in a variable.
Store integers in variables:
To verify that a variable is an integer, use the built-in type() function. If it outputs <class 'int'>, it's an integer.
Using Integers in Calculations
You can perform mathematical operations with integers. For example, you can add, subtract, and multiply them.
You can also use variables in mathematical operations.
Large Integers
Python can work with very large integers. Python integers have no maximum size limit.
You can use underscores to make large numbers easier to read. Python ignores the underscores when executing the code.
Integers vs Strings
The + operator performs addition for integers but concatenates (joins) strings. In the example below, both values are integers:
Now compare it with strings: