Skip to main content

Posts

Showing posts with the label int()

Implicit and Explicit Conversion in python

  #Lets take two variables a & b:- a = 14 print(type(a)) b = 14.66 print(type(b)) #Output: 14 has a datatype : <class 'int'> 14.66 has a datatype : <class 'float'> >>The output here shows what type of datatype variable 'a' and  'b' has. 'a' has integer datatype 'b' has float datatype  >> This type of conversion where python automatically converts one datatype into another is called as Implicit Conversion. >>Now lets take same variables for another type of conversion. a = 14 print(float(a)) As we all know that variable 'a' has an integer datatype but here we are explicitly converting that into float with the help of float(). #Output: 14.0 Here we can see that the output has a datatype float. b = 14.66 print(int(b)) Same goes here, in the above example we have seen that variable 'b' has a datatype float but here we are explicitly converting it into integer with the help of int(). #Output: 14