Summary - Data types
- Python course
- Beginner
- Lesson 18/116
- 5 min
Combine int, float, str and bool to write a profile card.
Summary - Data types
In this group you learned int, float, bool, str, None and type conversion.
- int is integer, float is decimal.
- bool is True/False; really an int.
- str is text; single or double quotes.
- None is the "no value" type; check with is None.
- int(), float(), str(), bool() do explicit conversion.
Now two tasks combine these concepts.
Practice Print the type conversion
Assign "19.99" to price_str. Assign float(price_str) to price. Then print print(price).
Starter code
# Do the conversionSample solution
price_str = "19.99"
price = float(price_str)
print(price)Expected output
19.99
Practice int and str together
Assign 50 to count. Assign str(count) to message. Then print print(message).
Starter code
# Convert int to strSample solution
count = 50
message = str(count)
print(message)Expected output
50
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which is wrong?
- int holds integers
- bool holds True/False
- float holds decimals
- None == True is True Correct answer
Explanation: None == True is False, not True.
2 Assign a bool value
is_ready = ____
print(is_ready)
is_ready = True
print(is_ready)
Explanation: is_ready = True assigns a bool.