Interview Question

What is type casting?

Type conversion creates a value of the requested type when supported.

💡 Concept ✅ Quick Revision 🐍 Python

Answer

Python commonly uses constructors and conversion functions to create a value of another type. • int(), float(), str(), list(), tuple(), and set() perform supported conversions. • Conversions can fail with TypeError or ValueError. • A conversion creates a new object rather than changing an object’s type in place.

💡 Simple Example

number = int('42') print(number + 1)

Output

43

⚡ Quick Revision

Type conversion creates a value of the requested type when supported.