# Type Conversion

> Changing a value into a new type. Text like "42" can become the number 42.

**Field:** Software Development  
**Category:** Programming Concepts  
**Also known as:** Type Casting, Casting, Type Coercion

## Think of it like

It is like swapping coins for a paper note. The money is the same, but the form changes.

## Definition

Type conversion turns a value of one data type into another. The text "42" can become the number 42, so you can do maths with it. When you ask for it in code, it is called casting. Some languages also convert on their own, which is called coercion. That can give odd results, like "5" + 1 making "51" in JavaScript.

## 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.

## Example code

```python
age = "12"
print(int(age) + 1)
# 13
```

int() turns the text "12" into the number 12, so adding works.

## Why it matters

Input from users and files usually arrives as text. It must be converted before it can be counted or compared.

## Common mistake

Trusting that text holds a number. Converting "twelve" fails, so check the input first.

## Three principles

- **Same value, new type.** Text 42 becomes number 42.
- **Asked or automatic.** Casting is asked; coercion is not.
- **Can fail.** Not every text is a number.

## Related terms

- [Data Type](https://learn.benibix.com/term/development/data-type)
- [String](https://learn.benibix.com/term/development/string)
- [Integer](https://learn.benibix.com/term/development/integer)
- [Floating-Point Number](https://learn.benibix.com/term/development/floating-point-number)
- [Runtime Error](https://learn.benibix.com/term/development/runtime-error)
- [String Concatenation](https://learn.benibix.com/term/development/string-concatenation)

## Taught in

- [Type Conversion and Strings](https://learn.benibix.com/learn/development-concepts/type-conversion-and-strings): Programming Basics, 7/18

![Six small cards in two rows. Type conversion turns the text 42 into the number 42. Concatenation joins Hello and Emma. A tuple holds three values in fixed slots. An enum lists RED, AMBER and GREEN. A built-in function len counts five letters in hello. A hard-coded line has a tax rate of 0.2 written straight into the sum.](https://learn.benibix.com/diagrams/dev7-working-with-values.svg)

---

Source: https://learn.benibix.com/term/development/type-conversion
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
