Python Logo

Introduction to Lists

Key Terms

List
An ordered list of data.
Square Brackets: [ ]
Square brackets come in opening([) and closing pairs (]). They are used to enclose lists and to access a specific index in a list.
Index
A non-negative number given to each element in a list to uniquely identify it.

Modifying Lists

Modifying a Single List Element

There are many ways to modify a list but one of the simplest ways is to directly modify a single element by supplying its index value and assigning a new value.


          shows = ['DBZ', 'Arrested Development', 'The Simpsons', 'Breaking Bad']
          # Reassign the value in index 2
          shows[2] = 'Batman'
          print('\n')
          # Print shows list to see changes
          print(shows)
        

          ['DBZ', 'Arrested Development', 'Batman', 'Breaking Bad']
        

Deleting Elements