Create lists with different types
Although it's not really common, a list can also contain a mix of Python types including strings, floats, and booleans.
You're now going to add the room names to your list, so you can easily see both the room name and size together.
Some of the code has been provided for you to get you started. Pay attention here! "bathroom"
is a string, while bath
is a variable that represents the float 9.50
you specified earlier.
This is a part of the course
“Introduction to Python”
Exercise instructions
- Finish the code that creates the
areas
list. Build the list so that the list first contains the name of each room as a string and then its area. In other words, add the strings"hallway"
,"kitchen"
and"bedroom"
at the appropriate locations. - Print
areas
again; is the printout more informative this time?
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
hall = 11.25
kit = 18.0
liv = 20.0
bed = 10.75
bath = 9.50
# Adapt list areas
areas = [____, hall, ____, kit, "living room", liv, ____, bed, "bathroom", bath]
# Print areas
____
This exercise is part of the course
Introduction to Python
Master the basics of data analysis with Python in just four hours. This online course will introduce the Python interface and explore popular packages.
Learn to store, access, and manipulate data in lists: the first step toward efficiently working with huge amounts of data.
Exercise 1: Python ListsExercise 2: Create a listExercise 3: Create lists with different typesExercise 4: List of listsExercise 5: Subsetting ListsExercise 6: Subset and conquerExercise 7: Slicing and dicingExercise 8: Subsetting lists of listsExercise 9: Manipulating ListsExercise 10: Replace list elementsExercise 11: Extend a listExercise 12: Delete list elementsExercise 13: Inner workings of listsWhat is DataCamp?
Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.