Loading

Quipoin Menu

Learn • Practice • Grow

Lists

A list is an ordered, mutable collection of items. It can contain mixed data types, and items are accessed by index. Lists are one of Python's most versatile data structures.

Creating Lists


fruits = ["apple", "banana", "cherry"]
mixed = [1, "hello", 3.14, True]
empty = []

Accessing Elements
Use zero‑based indexing. Negative indices count from the end.


print(fruits[0]) # apple
print(fruits[-1]) # cherry

Slicing
Extract a portion: `list[start:stop:step]`.


numbers = [0, 1, 2, 3, 4, 5]
print(numbers[1:4]) # [1,2,3]
print(numbers[::2]) # [0,2,4]
print(numbers[::-1]) # reversed

Common List Methods
  • `append(x)` – add element to end
  • `extend(iterable)` – add all elements of iterable
  • `insert(i, x)` – insert at index i
  • `remove(x)` – remove first occurrence of x
  • `pop(i)` – remove and return element at i (default last)
  • `index(x)` – return index of first occurrence
  • `sort()` – sort in‑place
  • `reverse()` – reverse in‑place

fruits.append("orange")
fruits.insert(1, "blueberry")
fruits.sort()
last = fruits.pop()
Two Minute Drill
  • Lists are ordered, mutable, and can contain mixed types.
  • Index from 0; negative indices count from end.
  • Slicing creates a new list.
  • Use methods like append, extend, insert, remove, pop, sort.
  • Lists are used for collections that need to change.

Need more clarification?

Drop us an email at career@quipoinfotech.com