Type Conversion

noun

say it: “TYP kun-VER-zhun” /taɪp kənˈvɜːrʒən/

Turning a value into another type, such as text into a number with int() or float(), or a number into text with str().

What is type conversion?

Type conversion turns a value into another type with int(), float() or str(). You need it all the time, because input() always gives you a string.

age_text = input("How old are you? ")   # e.g. "25"
age = int(age_text)
print(age + 1)  # 26

In a sentence

  • “Type conversion with str() let the program join the total into a message.”
  • “input() gives text, so type conversion with int() was needed before adding 1.”

Level: Novice · More Python terms at this level

Updated

In other subjects