Learn Python Numbers





Part 1


In Python we have three numeric types:


int


float


complex


Code Example:

                  
                  a = 5    # int
b = 3.4  # float
c = 2j   # complex
                
                


Float


Float also called "floating point number", is either positive or negitive number.


Use the type( ) function, to check the type of the variable.

Code Example:

                  
                  print(type(a))
print(type(b))
print(type(c))
                
                







Part 2

Float


Float also called "floating point number", is either positive or negitive number.


Code Example:

        
        a = 1.20
b = 2.0
c = -22.45
print(type(a))
print(type(b))
print(type(c))
      
      







Part 3

Int


Whole numbers are called integers


Code Example:

        
        a = 5
b = 6242145323
c = -5432523
print(type(a))
print(type(b))
print(type(c))
      
      







Part 4

Complex


Complex numbers are written with a "j" (imaginary part):


Code Example:

        
        a = 1+2j
b = 3j
c = -2j
print(type(a))
print(type(b))
print(type(c))
      
      







Part 5

Type Conversion


learn how to convert from one type to another in the next example:


Code Example:

        
        d = 4
         # int

e = 1.5
 # float

f = 3j
 # complex

 #convert from int to complex:
c = complex(f)

#convert from int to float:
a = float(e)

#convert from float to int:
b = int(d)



print(a)
print(b)
print(c)

print(type(a))
print(type(b))
print(type(c))
      
      







with us you can learn Python coding courses and many other Programming courses for free , our main goal is to allow students to learn Python lessons and web development courses in one place easily.


Navigation