Member-only story
Introduction
In the world of Python, numbers are more than just digits. They are the building blocks of your code, the foundation of your algorithms, and the key to unlocking the full potential of Python.
In this article, we will explore the different types of numbers in Python, how to use them, and some tricks that will make your coding journey easier and more efficient.
The Basics — Integers and Floats
Python supports various types of numbers, but the most commonly used are integers and floats. Integers are whole numbers, positive or negative, without any decimal points.
Floats, on the other hand, are numbers that do have decimal points.
# Integer
x = 10
print(type(x)) # <class 'int'>
# Float
y = 10.5
print(type(y)) # <class 'float'>
Mathematical Operations with Integers and Floats
Python supports all the basic mathematical operations you would expect, such as addition (+
), subtraction (-
), multiplication (*
), division (/
), and exponentiation (**
).