17 python as a calculator
Python can be used a calculator. Python has all the necessary operators and rules as you know from school.
print(4+5)
print(4*5)
print(5/2)
print(5%2)
print(5//2)
print(2+1/3*3)
out: 3.0
print((2+(1/3))*3)
out: 7.0
print(2**5)
Common operators
- a + b addition
- a - b subtraction
- a * b multiplication
- a / b division (float result)
Only following operators are a bit different than normal mathematical ones.
% is remainder operator. Remainder operator is used in a lot of question to find if a number is divisible by another number.
// is integer division.
** power operator. 2**5 is equal to 2*2*2*2*2