Python | Operator | Arithmetic Operators By. Shivansh Sir
PYTHON PROGRAMMING
PYTHON | ARITHMETIC OPERATOR
- Addition (+) :- Left और right operand को add करता है |
- Subtraction (-) :- Left operand से right operand को subtract करता है |
- Multiplication (*) :- Left और right operand को multiply करता है |
- Division (/) :- Left operand से right operand को divide करता है |
- Modulus (%) :- Left operand से right operand को divide करके remainder return करता है |
- Floor Division (//) :- Left operand से right operand को divide करके floor value return करता है |
- Exponent (**) :- Left operand का power right operand होता है |
PYTHON | ARITHMETIC OPERATOR | ADDITION ARITHMETIC OPERATOR
Source Code
print(5 + 6)
print(5.6 + 7.9)
Output
11
13.5
PYTHON | ARITHMETIC OPERATOR | SUBTRACTION ARITHMETIC OPERATOR
Source Code
print(5 - 6)
print(5.6 - 7.9)
print(7.9 - 5.6)
Output
-1
-2.3000000000000007
2.3000000000000007
PYTHON | ARITHMETIC OPERATOR | MULTIPLICATION ARITHMETIC OPERATOR
Source Code
print(5 * 6)
print(5.6 * 7.9)
print(7.9 * 5.6)
Output
30
44.24
44.24
PYTHON | ARITHMETIC OPERATOR | DIVISION ARITHMETIC OPERATOR
Source Code
print(5/2)
print(4/2)
print(4.6/2.6)
print(2/4)
print(0/4)
print(4/0)
Output
2.5
2.0
1.769230769230769
0.5
0.0
print(4/0)
ZeroDivisionError: division by zero
PYTHON | ARITHMETIC OPERATOR | MODULUS ARITHMETIC OPERATOR
Source Code
print(4%2)
print(4%5)
print(4%3)
print(4.5%3.5)
Output
0
4
1
1.0
PYTHON | ARITHMETIC OPERATOR | FLOOR DIVISION ARITHMETIC OPERATOR
Floor Division Arithmetic Operator in Python
Source Code
import math
print(4/3)
print(4//3)
print(math.floor(4/3))
print(3/4)
print(3//4)
print(math.floor(3/4))
Output
1.3333333333333333
1
1
0.75
0
0
PYTHON | ARITHMETIC OPERATOR | EXPONENT ARITHMETIC OPERATOR
Source Code
import math
print(4**2)
print(math.pow(4, 2))
print(4**10)
print(math.pow(4, 10))
Output
16
16.0
1048576
1048576.0
Comments
Post a Comment