WHAT IS THE DIFFERENCE BETWEEN IMPLICIT AND EXPLICIT TYPECASTING-:
Typecasting-:
Changing the type conversion from one data type to other .For example changing the float value to the integer value or the integer value to the float value . this can be done in two ways which are Implicit and explicit type casting , first we will understand the Implicit type casting so lets get started with it .
Implicit type casting means changing of data type from one data type to another without loosing its original meaning , Without changing its value stored inside a variable .
It converts a smaller type to a larger type size.
For example-:
Num = 9
Double = Num # // Automatic casting: int to double
print(Num) // Output-: 9
print(Double) // Output-: 9
so in implicit type casting the values remains same.
Num = 9
Double = Num # // Automatic casting: int to double
print(Num) // Output-: 9
print(Double) // Output-: 9
so in implicit type casting the values remains same.
Explicit Typecasting -:
Explicit type casting means changing of larger type to a smaller size type of a variable.
This is done manually by placing the type in parentheses in front of the value.
For example-:
Double = 9.78
Int = int(Double) # Manual casting: double to int
print(Double) # Outputs 9.78
print(Int) # Outputs 9
Double = 9.78
Int = int(Double) # Manual casting: double to int
print(Double) # Outputs 9.78
print(Int) # Outputs 9
so in explicit type casting the values do not remains same.
For more comment below
0 Comments