Search the courses, subjects, tracks, games and features, or jump straight to a page.
Learn it your way
A short class with Sarah and her students. The other ways are under More.
Sign up free to listen. Transcripts are free to read.
Today we're going to learn how to create lists in Python! Lists are an ordered collection of items. Who can tell me how we define a list?
Is it with square brackets?
Exactly! We use square brackets, like this: [1, 2, 3]. Can anyone tell me what types of data we can store in lists?
We can store numbers, strings... even other lists?
Correct! Lists can hold different data types. For example, mixed = [1, 'apple', 3.14, True] combines multiple types in one list. Remember, this versatility is what makes lists so powerful!
And they're mutable, right?
Yes! That means we can change them after we've created them. Let's proceed to create some lists together!
Let's look at some examples. First, we'll create a list of numbers. Can anyone help me write that?
How about numbers = [1, 2, 3, 4, 5]?
Perfect! Now, who can give me an example of a fruit list?
What about fruits = ['apple', 'banana', 'mango']?
Exactly! We now have a list of fruits. Can someone tell me how to create an empty list?
It's just empty brackets, like this: empty = [].
Great! Remember, empty lists can be useful when you want to add items later. Let’s recap: a list is defined by square brackets, can hold mixed data types, and can be empty.
Let's summarize the key features of lists. Who remembers what makes them special?
They are ordered, so the first item is always at index 0!
Yes! And because they are mutable, we can modify them. Can anyone give an example of lists holding different types?
We could have a list like data = [42, 'Hello', 3.14]!
Exactly! Lists can be a mix of many types. Always remember this when storing related items together!
So they are super flexible for many tasks in programming!
That's right! Flexibility is key. Any last questions before we end today’s discussion on creating lists?
A list is like a box, full of things you can mix, filled with data of all kinds, just like candy sticks.
Imagine a treasure chest (the list) where you can store different treasures (data types), and you can open it any time to change what’s inside.
Remember with 'LIMES': L for List, I for Indices, M for Mutable, E for Empty, S for Storage of multiple types.
'SOME': S for Square brackets, O for Ordered, M for Mutable, E for Elements can be of any type.
Term
What is a list?
Click to flip
Term
Define mutable in the context of lists.
Click to flip
Term
How do you create an empty list?
Click to flip
This section explains how to create lists in Python, showcasing different examples of lists along with their features.
In this section, you will learn how to create lists in Python using examples of numeric, string, and mixed data. It also touches upon the concept of empty lists and highlights the fundamental properties of lists in Python.
In Python, lists are incredibly versatile data structures that allow you to store collections of items. They are defined by enclosing items in square brackets (e.g., [1, 2, 3]). A list can contain various data types including integers, strings, and even other lists, allowing for great flexibility in data storage.
numbers = [1, 2, 3, 4, 5]fruits = ["apple", "banana", "mango"]mixed = [1, "apple", 3.14, True]empty = []Understanding how to create lists is foundational for working with data in Python, especially in applications like data science and AI.