Python 3D Academyবাংলা

Lists in Python

Chapter 8: Lists

5 short lessons, with 3D animations, quizzes and coding tasks.

The lessons

  1. Making lists

    A list keeps many values in one variable, in order, and you reach each one by its index, just like the characters of a string.

  2. Changing a list

    A list is mutable: append, insert and [i] = x put items in, and pop and remove take them out, all changing the same list.

  3. Looping over a list

    for item in my_list: visits every item of the list in order, putting each one in the loop variable, so you can print it, add it up, or keep it.

  4. Sorting and other list methods

    nums.sort() puts the list itself in order, while sorted(nums) gives back a new sorted list and leaves the old one alone.

  5. Lists of lists

    A list can hold other lists, so grid[r] is a whole row and grid[r][c] is the item in row r, column c.