🧩Type Conversion
Also known as Type Casting, Casting, Type Coercion
Changing a value into a new type. Text like "42" can become the number 42.
Think of it like
It is like swapping coins for a paper note. The money is the same, but the form changes.
Example
A form gives Lucy's app the age as the text "12". The app converts it to the number 12 before it adds 1.
Why it matters
Input from users and files usually arrives as text. It must be converted before it can be counted or compared.
Definition
Example code
python
age = "12"
print(int(age) + 1)
# 13Common mistake
Key takeaways
- 1Same value, new type. Text 42 becomes number 42.
- 2Asked or automatic. Casting is asked; coercion is not.
- 3Can fail. Not every text is a number.