What is Python Casting with example?
Ask by ICSM Computer
Updated 15 Sep 2025
There are two main types:
1. Implicit Casting (Type Conversion)
Done automatically by Python (no data loss).
For example, when combining an integer with a float:
2. Explicit Casting (Type Conversion)
Done manually by the programmer using functions:
int()→ converts to integerfloat()→ converts to floating-point numberstr()→ converts to stringbool()→ converts to booleanExamples:
Summary Table of Casting Functions in Python:
int(x)int("12") → 12float(x)float("3.5") → 3.5str(x)str(99) → "99"bool(x)bool(0) → False