Numbers
In today’s world, numbers are found everywhere when programming or coding. It is used in simple calculations to complex scientific calculations and financial modeling.
It is very easy to work with numbers in Python language. Python language has many powerful built-in numeric types and math functions.
Section 1: Basic Operations
If you want to perform basic arithmetic operations in Python, then it is very easy to do that.
Number Types -There are three numeric types in Python:
1.
Integer - It is a whole number and can’t have a decimal point. It can have positive, negative or zero values.
Examples are 10, -5, 0. If you want you can also use underscores for better readability.
Example: You can write 5_00_000 instead of 500000.
Example:

2.
Float - It is a real number that contains a decimal point.
Examples: 3.14, 2.542, -1.94, and 1.2e³ or 1200.0
It is used to represent continuous values like price, temperature, or distance.
Example:
3.
Complex Number -
It has mainly two parts — a real part and an imaginary part.
It is written as a + bj.
Example: If we write 5 + 3j, then 5 is the real part and 3 is the imaginary part.
Complex numbers are mainly used in advanced areas like AI algorithms and electrical engineering.
Example:

Below is an example of different types of arithmetic operations:
Example:

Note: If both the operands (a and b, in this case) are of integer type, then division (/) operator always returns a float number or decimal value.
Section 2: Order of Operations and Scientific Notation
If you write a math expression in Python language, then it follows an order called PEMDAS. It decides which operation will be executed first.
The full form of PEMDAS is :
P – Parenthesis
E – Exponent
M – Multiplication
D – Division
A – Addition
S – Subtraction
Let’s understand rule order:
1. Anything from parenthesis () is calculated first.
2. After that, Exponent is calculated.
3. Then multiplication and division are executed from left to right side.
4. At last, addition and subtraction are executed from left to right side.
Example:

In the above example, if you want the addition operation to be performed first, then you can use parentheses () operator as shown below :
Example:
In short, if you want to control the order of execution, then you can use parentheses ( )
Scientific Notation
In Python, you can write small or large numbers using scientific (exponential) notation.
Example:
Whenever you write e or E letter in Python language, then it means to multiply by 10 to the power of.
Two simple examples are given below for better understanding:• Meaning of 5e2 is 5 × 10² = 500.0
• Meaning of 5e-3 is 5 × 10⁻³ = 0.005
Section 3: Type Casting Functions
If you want to change the data type or number type from one to another, then you can use type casting. For example, Python allows you to change a decimal number to an integer or a string to an integer.
Example:

It is important to remember that type casting is used to keep calculations accurate and also helps to avoid errors when we mix different data types.
Few examples of Type Casting functions in Python language:
There are some built-in functions (in Python) which are used to convert values from one data type to another.

Section 4: Number Representation and Storage in Memory
If you want to write efficient programs in Python, then you should have a good understanding of how numbers are stored and represented inside memory.
a) Integers in Memory:
In Python language, an integer number is stored in binary format. Each integer number is converted into binary form and stored inside memory.
If you want to see the binary form of any integer number, then you can use the format() function.
Example:

In above example, format function has converted integer x into its binary form (1010).
b) Floats in Memory:
If you write a decimal number (3.25), it cannot store it exactly in memory. Computers can only understand binary form (0 & 1).
So, IEEE 754 Floating Point format is used to convert a float number to binary form.
Example:
If you write the following code in Python:

Then, this number is divided into two parts:
• Whole part – 10
• Decimal part – 0.75
In Python language, both parts are converted to binary form separately.
a) Firstly, the whole part is converted:
10 in binary form = 1010
b) Now, the decimal part is converted (0.75).
It multiplies by 2 repeatedly and records the whole number each time as shown below:
0.75 × 2 = 1.5 → 1
0.5 × 2 = 1.0 → 1
So, 0.75 in binary form = .11
Now, you can combine both parts:
10.75 = 1010.11 (binary form)