Python Tutorial · Revision notes

Python Lists

A list is an ordered, mutable collection that can hold items of any type. This chapter covers creating and slicing lists, the built-in list methods, list comprehensions and how a list differs from a tuple.

Quick revision

  • List: ordered, mutable, allows duplicates, [ ]
  • Slicing returns a new list and excludes stop
  • append adds one object; extend adds elements
  • sort/reverse/append/remove return None
  • Comprehension: [expr for x in it if cond]
  • Tuple: immutable, hashable, (5,) needs a comma
Read the full Python Lists notes on Doubtclip →