What are the Numbers in Python?
โ Integers and floats are the two types of numbers in python. Integers present whole numbers like 5,-5 while floats represent decimal numbers like 3.412 the other type of number in python is the complex number which defined as (a+bj)where 'a' is the real part and b is the imaginary part. (example: 5+3j is a complex number.)
Arithmetic operations with numbers:
- + Addition
print(6 + 5) #11
- - Subraction
print(6 - 5) #1
- * Multiplication
print(6 * 5) #30
- / Division
print(6 / 5) #1.2
- // Floor Division (Eg:5//2==2) nothing but deletion of decimal value
print(6 // 5) #1
- % Remainder
print(6 % 5) #1
- ** Exponent (Eg: 5**2==25)
print(6 ** 5) #7776
PYTHON follows the 'PEMDAS' rule for operator 1st preference
- P-parentheses
- E-exponents
- M-multiplication
- D-division
- A-addition
- S-subtraction
Example 1:
print(2-2**4/4*3)
#-10.0 (*division forms into decimal)
Example 2:
print(5 + (4 - 2) * 2 + 4 % 2 - 4 // 3 - (5 - 3) / 1)
#6.0 (*division forms into decimal)
ย