Type Conversion
├── Implicit → automatic
└── Explicit → manual (type casting)Type Conversion (implicit) → Python automatically converts one data type to another
ans = 5 + 10.0
print(ans, type(ans)) # int → floatoutput
15.0 <class 'float'>Important
Python converts smaller type to bigger type
int → float
Type Casting (explicit) → done manually by the developer
We use functions like int(), float(), str()
ans = int(5 + 10.0)
print(ans, type(ans))output
15 <class 'int'>Attention
- Type casting works only with compatible data types
- In implicit conversion, Python decides
- In explicit casting, the developer controls the type