list.append()

Python · Lists

Theory

.append(item) adds one item to the end of a list, modifying the list in place. sales = [100, 250, 300] followed by sales.append(400) leaves sales as [100, 250, 300, 400]. The method returns None, so writing sales = sales.append(400) is a classic bug: it throws your list away and stores None.

append() always adds exactly one item, whatever that item is. Appending a list nests it as a single element: [1, 2].append([3, 4]) produces [1, 2, [3, 4]] with length 3, not 4; use extend() if you want the items added individually. Appending is fast, amortised O(1), because a list keeps extra capacity at the end and only occasionally grows its underlying array. That is why the common pattern of starting with an empty list and appending inside a loop scales well.

Why we use it

Data is often collected one piece at a time: a row read from a file, a result from an API, a value computed in a loop. append() is the standard, efficient way to grow a list as each new item arrives.

When to use it

Use append() to add one item at the end. Use extend() or += to add several items from another list, and insert() if the item must go at a specific position. If you are just transforming another list, a list comprehension is often cleaner.

How it works

  1. Call sales.append(400)
  2. Spare capacity at the end? Yes: Write into the next slot. No: Grow the array, copy, then write.
  3. Increase the list's length by 1
  4. Return None (the list itself was changed)
  5. print(sales) shows [100, 250, 300, 400]

Syntax

list.append(item)

Example

sales = [100, 250, 300]
sales.append(400)
print(sales)

Key points

Python topics

Getting Started

Variables & Data Types

Operators

Strings

Lists

Tuples

Sets

Dictionaries

Control Flow

Loops

Functions & OOP

Working with Data

Tooling & Errors

File Handling

Exception Handling

NumPy Library

Pandas Basics

Data Cleaning

Combining DataFrames (SQL Joins & Unions)

GroupBy & SQL-Style Analytics

Reshaping & Workflow

Data Visualization

Machine Learning (Scikit-Learn)

Advanced Python & AI

T
Tech Town
Log InSign Up Free
Home SQL Python DSA Power BI Snowflake Databricks Spark Gen AI Practice Problems Contest Blog

Python for Data Analysts

From basics to business insights — the complete step-by-step Python roadmap. Click any topic in the sidebar to open it right here.

{{ sectionCount }}
Sections
{{ topicCount }}
Topics
Free
Forever
Hands-on practice Practice Python Online 141 Python questions for data analysts — strings, records, dates, statistics and regex — with hidden tests and instant verdicts. Start practising →
Section {{ sec.num }}

{{ sec.label }}

Python  /  {{ current.sectionLabel }}  /  {{ current.name }}

{{ current.name }}

Theory

{{ current.def }}

Why we use it

{{ rich.why }}

When to use it

{{ rich.when }}

Diagram

{{ rich.dg.caption }}

{{ tb.title }}
{{ c.v }}
{{ rich.dg.op }}
➜
{{ rich.dg.output.title }}
{{ c.v }}
{{ nd.label }}
{{ nd.sub }}
{{ nd.label }}
{{ nd.sub }}
{{ rich.dg.left.title }}
{{ it }}
{{ rich.dg.right.title }}
{{ it }}
Flowchart — how it works
{{ nd.text }}
{{ nd.text }}
◇ {{ nd.text }}
Yes → {{ nd.yes }}
No → {{ nd.no }}
Syntax
{{ current.syntax }}
Example
{{ current.example }}
▶ Try It Live — runs real Python 3.12 in your browser (first run loads the engine)
{{ liveOutput }}
{{ liveError }}
Key Points — click to check off as you learn
  • {{ pt.mark }} {{ pt.text }}

Share this topic