Basic Numeric operations - Python as calculator
Learn the basic operations. Enter into phython interepter by typing python in your terminal / command prompt
1
2
3
4
5
(base) ~ ➤ python
Python 3.8.8 (default, Apr 13 2021, 12:59:45)
[Clang 10.0.0 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
Addition
1
2
3
4
5
>>> 1+2
3
>>> 5+6
11
>>>
Subtraction
1
2
3
4
5
6
>>> 1-2
-1
>>> 5-9
-4
>>> 11-2
9
Multiplication
1
2
3
4
>>> 2*2
4
>>> 7*9
63
Division
1
2
3
4
>>> 3/2
1.5
>>> 9/4
2.25
Modulus
Note: It return the reminder value
1
2
3
4
>>> 3 % 2
1
>>> 2 % 5
2
Floor Division
Note: Floor division gives result ignores any numbers post decimal
1
2
3
4
>>> 8/3
2.6666666666666665
>>> 8//3
2
In above you could see .6666666666666665
been ignored and just 1 been given as result
Power of
To get 24
1
2
>>> 2**4
16
You can do the same above by assigning it to variables
1
2
3
4
5
6
>>> a = 10
>>> b = 20
>>> a * 2
20
>>> b + b + a
50
Priority
Python follows BODMAS
to perform operations
- Bracket of
- Division
- Multiplication
- Addition
- Substraction Modulus is performed last unless mentioned within brackets
Operations are performed in above order
Thanks for reading till end.
Followus on @techpechu
Join Our Discord
We do run a youtube channel in Indian regional language Tamil called TechPechu. Do subscribe us for moral support. Happy Learning.