Back to Chapters
Chapter Progress: 0 %0 / 7 Lessons Read
‹›

4. Lists

4.1 Create a list

Highlights & notes

Select lesson text to highlight it, or tap Add note.

    Bookmarks

    Bookmark a lesson to see it here.

      A list stores many values in one variable, in order. Write the values inside square brackets [ ], separated by commas.

      In data engineering you use lists all the time: a batch of file names, a column of values, the rows you read from a CSV.

      Example

      Python
      files = ["orders.csv", "users.csv", "events.csv"]
      print(files)
      print(len(files))
      print("users.csv" in files)
      Output
      ['orders.csv', 'users.csv', 'events.csv']
      3
      True
      • Lists keep their order and allow duplicates.
      • One list can hold mixed types: [101, "Asha", 2500.0, True].
      • len(list) gives the number of items. x in list checks if a value is there.
      Must Know:

      An empty list is []. You will often start with one and fill it later: rows = [].

      Practice in Python

      Make a list cities with "Delhi", "Noida" and "Pune". Print the list, then print how many cities it has.

      Expected output
      ['Delhi', 'Noida', 'Pune']
      3

      Reference solution
      cities = ["Delhi", "Noida", "Pune"]
      print(cities)
      print(len(cities))

      Question 1 · Easy

      Which one creates a list?

      Question 2 · Medium

      ids = [7, 7, 9]. What is len(ids)?

      Question 3 · Medium

      cols = ["id", "name"]. What does "age" in cols give?

      Key takeaways

      Lists hold ordered values in [ ]. Use len() to count and in to check membership.

      Lesson 14 of 67

      Save your progress

      Start free and your progress, code and notes stay saved. Free for 1 month, no card needed.

      Start free Log in
      PreviousCreate a list
      Save your progress free for 1 month. Start free · Log in