Casting
Use int(), float() and str() to convert values. int("5") gives 5 and str(5) gives "5". Converting something that does not look like a number, such as int("abc"), raises a ValueError.
Example
print(int("5") + 1)
print(float("2.5") * 2)
print(str(10) + " apples")
print(int(7.9))
print(bool(0), bool("hi"))Result
6 5.0 10 apples 7 False True
Exercise
Turn the text into a whole number.
total = ("5") + 1
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.