What is type-casting?

Type-Casting

Casting is when you convert a variable value from one type to another. This is, in Python, done with functions such as int() or float() or str() . A very common pattern is that you convert a number, currently as a string into a proper number.

The process of conversion of data from one type to another is known as type casting.

There are two types of it-

  • Implicit-This type of casting is automatically done by the compiler without user interference.
  • Explicit-This type of casting is done by user by using type cast operators

For example, in an expression mixing integer and floating pointed numbers (like 5 + 0.1), the compiler will automatically convert integer representation into floating point representation so fractions are not lost.