Python integer (int), is a whole number, positive or negative, without decimals, of unlimited length. The integers are zero, positive, or negative whole numbers without a fractional part and having unlimited precision, e.g. 0, 100, -10.
Python integers
A simple example code uses the type()
method to get the class name.
x = 1
y = 35636363
z = -10001000
print(type(x))
print(type(y))
print(type(z))
Output:
Python allows you to perform various arithmetic operations on integers, such as addition, subtraction, multiplication, division, and more. For example:
a = 10
b = 5
# Addition
result_addition = a + b # Result: 15
# Subtraction
result_subtraction = a - b # Result: 5
# Multiplication
result_multiplication = a * b # Result: 50
# Division
result_division = a / b # Result: 2.0 (Python 3.x returns a float)
# Floor Division (returns only the integer part of the division)
result_floor_division = a // b # Result: 2
# Modulus (returns the remainder of the division)
result_modulus = a % b # Result: 0
Integers in Python are very flexible and widely used in various programming tasks.
Do comment if you have any doubts or suggestions on this Python basic topic.
Note: IDE: PyCharm 2021.3.3 (Community Edition)
Windows 10
Python 3.10.1
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.