Prahlad Inala
Prahlad Inala

Prahlad Inala

Numbers in Python

Numbers in Python

Prahlad Inala
·Jul 3, 2021·

1 min read

Subscribe to my newsletter and never miss my upcoming articles

Play this article

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:

  1. + Addition
     print(6 + 5)
     #11
    
  2. - Subraction
     print(6 - 5)
     #1
    
  3. * Multiplication
     print(6 * 5)
     #30
    
  4. / Division
     print(6 / 5)
     #1.2
    
  5. // Floor Division (Eg:5//2==2) nothing but deletion of decimal value
     print(6 // 5)
     #1
    
  6. % Remainder
     print(6 % 5)
     #1
    
  7. ** Exponent (Eg: 5**2==25)
     print(6 ** 5)
     #7776
    

PYTHON follows the 'PEMDAS' rule for operator 1st preference

  1. P-parentheses
  2. E-exponents
  3. M-multiplication
  4. D-division
  5. A-addition
  6. 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)
 
Share this