What is a Python List?

Python lists let you store multiple values in one variable using square brackets. Instead of creating separate variables for each data point, you can group them together, and lists can hold any type of data, including other lists.
Chapters
By now, you've played around with different data types. On the number side, there's a float to represent a real number and the.
Int to represent an integer. Next, we also have str, short for string, to represent text in Python and.
Bool, which can be either true or false.
You can save these values as a.
Variable, like these examples show.
Each variable then represents a single value. As a data scientist, you'll often want.
To work with many data points. If you, for example, want to measure the height of everybody in your family and store this information in Python, it would be inconvenient to create a new Python variable for each point you collected.
Right? What you can do instead is store.
All this information in a Python list.
You can build such a list with square brackets. Suppose you ask your two sisters and parents for their height in meters. You can build the list as follows. Of course. Also, this data structure can be referenced to with a variable. Simply put, the variable name and the.
Equal sign in front, like here.
A list is a way to give.
A single name to a collection of values.
These values or elements can have any type. They can be floats, integer, booleans, strings.
But also more advanced Python types, even lists.
It's perfectly possible for a list to contain different types as well. Suppose, for example, that you want to add the names of your sisters and parents to the list, so that you.
Know which height belongs to who. You can throw in some strings without issues.
But that's not all. I just told you that lists can also contain lists themselves. Instead of putting the strings in between the numbers, you can create little sublists.
For each member of the family.
One for Liz, one for Emma, and so on. Now you can tell Python that these sub lists are the elements of another.
List that I named, FAM2.
The little lists are wrapped in the square brackets and separated with commas.
If you now print out fam2, you.
See that we have a list of lists. The main list contains four sub lists.
We're dealing with a new Python type here.
Next to the strings booleans and integers and floats, you already know the lists.
These calls show that both fam and fam2 are lists. Remember that I told you that each type has specific functionality and behavior associated.
Well, for lists this is also true. Python lists host a bunch of tools to subset and adapt them. But let's take this step by step and have you experiment with list creation. First.
More from Richie

#359 My Best Friend is AI with Valerie Tiberius, Professor of Philosophy at University of Minnesota

How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon

#358 How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon







