Exercises
Data Types
3 tasks. Write the code, press Check, and the page runs it against a real Python interpreter.
Exercise 1Passed
Print the type of each of the four values, one per line.
Python
values = [42, 3.14, "hello", True]
# print the type of each
Loop over the list and call type() on each item.
values = [42, 3.14, "hello", True]
for value in values:
print(type(value))Exercise 2Passed
result is None. Print True only if it really is None, using the right test.
Python
result = None
# print whether result is None
Comparing with == is not the idiomatic test here.
result = None
print(result is None)Exercise 3Passed
Show that a string cannot be changed in place: print the uppercase version, then print the original unchanged.
Python
text = "abc"
# print the uppercase version, then the original
upper() hands back a new string rather than changing text.
text = "abc"
print(text.upper())
print(text)