Guido van Rossum created 'Python' which is a high-level and object oriented programming language in 1991. With emphasis on code readability, and its syntax allows programmers to express their concepts in fewer lines of code and almost like human readable language.
That's how the journey of learning the language of snake starts!
There are various data types in Python. Today we will only talk about Numbers and how to do basic math in Python. We know that there are two types of basic numbers in arithmetic. They are as follow:
Positive or negative whole numbers (without a fractional part).
For example: 10,5000000,-35
Any real numbers with “decimal” points or floating-point representation.
For example: -5.678,190.90
And with either of these numbers you can perform basic arithmetic as you would expect.
Here, 1 and 2 are operands, and "/" is the operator computing multiplication in python. We cannot use ÷ for this command. Division of numbers always yields a float.
Basically it's the power operator. Here, 2 and 4 are operands, and "**" is the operator computing exponents in python.
🟢Now we will introduce to two more exciting arithmetic operations that we will use regularly in Python. i.e. floor division and modulus.
In this arithmetic operation, the double-backslash operator (//) is the floor division operator.
Floor division of integers results in an integer. If one of the operands is float, then the floor division results in a float.
Here we can see, 7 divided by 5 yields 1.4 . But while using the floor division (//), it basically discards the part after the decimal point and returns a whole number by flooring the value to the nearest integer number. i.e. 1
In this arithmetic operation, the percentage sign (%) is the modulus operator and it basically returns the remainder after division. It works as a brilliant checker for finding odd or even number. **
To check whether the number is odd or even, we have to **mod by 2 and if the remainder yields zero then its a even number. Otherwise, the number is odd.
We can see that 4 divide by 2 yields quotient 2 and remainder 0. So the number is even.
We know that Python executes from top to bottom and reads code from left to right. Now, let us see a compound expression below:
Here, according to PEMDAS, operations in brackets should be carried out first. After that, from left to right we can see that next in line is multiplication and then division. Lastly, addition is done.
That's all for today! Feel free to ask me any question if you don't understand.