Python Fundamentals / Getting started
Lesson 10 of 38
Type conversion
Convert between types with int(), float(), str() and bool(). Converting text that isn't a number, like int("cat"), raises a ValueError.
Key points
- str(5) gives "5"
- int("7") gives 7
- type(x) tells you the type
print(int("12") + 3) # 15
print(str(12) + "3") # 123Quiz · +10 XP
What does str(4) + str(4) give?
Log in to save progress and earn XP.