Learn Casting in python for the absolute beginner (2021 grasp basic python online with role model)

Learn Casting in python for the absolute beginner (2021 grasp basic python online with role model)



Learn Casting in python for the absolute beginner



Python Casting:

The Python casting can be simply defined as converting a variable from one data type to another data type 

-> This python casting will be done by using the data types 
  • int()
  • float ()
  • str()   

int(): 

The int constructs an integer number from integer literal

float(): 

The float data type constructs a float number from an integer  literal 

str(): 

The str data type constructs a string from a wide variety of data types


Example: 

Integers

->  x = int(3)  # x will be 3
      y  = int (2.8) # y will be 2
      z  =  int("1")  # z will be 1

output:  >>>> 3
                       2 
                       1  

FLoats  

-> x =  float(3) # x will be  3.0 
    y =   float (2) # y will be 2.0
    z =   float ("1") # z will be 1.0

output: >>>> 3.0 
                      2.0
                      1.0

Strings

-> x =  str("z2") # x will be z2 

output: >>>> z2

Post a Comment

Previous Post Next Post