Lists can contain more than just numbers.
Let’s revisit our classroom example with heights:
- Noelle is 61 inches tall
- Ava is 70 inches tall
- Sam is 67 inches tall
- Mia is 64 inches tall
Instead of storing each student’s height, we can make a list that contains their names:
names = ["Noelle", "Ava", "Sam", "Mia"]
We can even combine multiple data types in one list. For example, this list contains both a string and an integer:
mixed_list_string_number = ["Noelle", 61]
Lists can contain any data type in Python! For example, this list contains a string, integer, boolean, and float.
mixed_list_common = ["Mia", 27, False, 0.5]
Let’s experiment with different data types in our own lists!
Add any additional string to the end of the list
Create a new list called
sam_height_and_testscore that contains:
- The string
"Sam"(to represent sam’s name)
- The number
67(to represent sam’s average grade)
- The float
85.5(to represent sam’s score)
- The boolean
True(to represent sam passing the test)
Make sure to write the elements in exact order.