List Objects

Besides strings, integers, and floats, lists are also an intensely used object type in Python. 

👉A list object is used to represent an array of other objects. For example, in the code below we have two lists. One in line 5 and one in 6. The parts dates = and temperatures_celsius = before the lists are optional variable assignments. You can ignore it for now. We will cover variables in the next lecture.

The above program generates a graph of temperatures by day. We need different object types to be able to build this graph. We need numbers such as floats or integers to represent the temperatures, and we need strings to represent things like graph labels and dates.

And, we also need another object to represent arrays of data and that is the list object. A list can be represented as an array of objects each separated by commas and the array enclosed in square brackets. The pyplot object which we will cover later on will get that list and use the objects in that list to construct the graph x and y axes.

👉A list can contain any type of object and any number of objects as far as the computer RAM allows. You can even store other lists inside a list. 

Below you will find some more list examples. Try adding some more lists in the next lines, and execute the program. If you don't get an error, that means you defined the lists correctly. You can click the last two message icons for list ideas.


Next Lecture
Recommended Course

Python Mega Course: Learn Python in 60 Days, Build 20 Apps
Learn Python on Udemy completely in 60 days or less by building 20 real-world applications from web development to data science.