Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Python · Class

list

list is Python’s mutable sequence type. Create one with a literal, comprehension, or list(iterable); construction preserves the iterable’s item order.

How it works

list creates a mutable sequence, either empty or populated from an iterable. Its elements preserve the iterable’s order, and the sequence supports indexing, slicing, iteration, concatenation, repetition, and in-place mutation.

Syntax

list([iterable])

Parameters

NameTypeDescription
iterableiterableOptional iterable whose items populate the new list in iteration order.

Returns

A new list containing the iterable’s items in the same order; with no argument, an empty list.

Key points

  • list is one of Python’s three basic sequence types, alongside tuple and range.
  • Lists are mutable and are typically used to hold collections whose elements have broadly similar roles.
  • Use [] to create an empty list.
  • List literals place comma-separated values inside square brackets.
  • List comprehensions provide a compact construction form that iterates over another iterable.
  • The constructor supports both an empty list and a list populated from an iterable.
  • Construction preserves each input item and its iteration order.

Common mistakes

  • In-place mutating methods such as append, extend, sort, and reverse return None, not the list.
  • Constructing from an iterable copies its references into a new list in iteration order; it does not deep-copy the contained objects.

Example: Construct and mutate a list

numbers = list(range(1, 4))
numbers.append(4)
print(numbers)  # [1, 2, 3, 4]

Creates a list from an iterable, then mutates it by appending one item.

When to use it

Materialize iterable data

Materialize an iterable so it can be indexed, sliced, or traversed repeatedly.

Build computed collections

Collect values produced by a comprehension or loop for later processing.

Manage mutable sequences

Maintain an ordered, mutable collection whose contents change over time.

Interview questions

QWhat does the list constructor do?

list(iterable) accepts an iterable and creates a new list containing the iterable’s items in the same order. The iterable can be a sequence, another container that supports iteration, or an iterator object.

Follow-up: What happens with an iterator? It is consumed as the list is built, so later iteration begins wherever that iterator was left.

QWhy choose a list instead of a tuple?

A list is a mutable sequence, so its elements can be changed after creation. Lists are commonly used for collections whose items are generally homogeneous, although Python does not enforce a single element type.

Follow-up: How would you prevent accidental mutation? Use a tuple for a fixed sequence, or expose an immutable interface where appropriate.

QHow can a list be created?

Lists support square-bracket literals, list comprehensions, and the list() or list(iterable) constructor. An empty list can be written as [], while items in a literal are separated by commas.

Follow-up: When is a comprehension preferable? Use it when transforming or filtering an iterable concisely; use list(iterable) when direct materialization is all that is needed.

  • tuple
  • range
  • dict
  • set
  • collections

Source: Built-in Types. Checked 2026-10-15.