List Methods
3 min read ·
Python lists come with a rich set of built-in methods that allow you to add, remove, search, modify, and organize data efficiently.
Below is a complete and accurate table of all list methods.
All Python List Methods (Table)
| Method | Description |
|---|---|
append(x) | Adds an item to the end of the list |
extend(iterable) | Adds elements of an iterable to the list |
insert(i, x) | Inserts an item at a specific index |
remove(x) | Removes the first occurrence of a value |
pop(i) | Removes and returns item at index (default last) |
clear() | Removes all items from the list |
index(x) | Returns index of first occurrence of value |
count(x) | Returns number of times value appears |
sort() | Sorts the list |
reverse() | Reverses the order of the list |
copy() | Returns a shallow copy of the list |
Python Collections (Arrays)
Python does not have traditional arrays like some other languages.
Instead, lists are used as dynamic arrays.
Why lists are used as arrays:
- Can store multiple values
- Can grow or shrink dynamically
- Support indexing and slicing
- Can store mixed data types
The list() Constructor
The
list() constructor is used to create a list from another iterable.From Tuple
From String
From Range
Using type() with Lists
The
type() function is used to check the data type of a variable.List Items – Data Types
A list can store multiple data types in a single list.
Same Data Type
Mixed Data Types
Nested Lists
Important Characteristics of List Items
- List items are ordered
- Indexing starts from
0 - Supports negative indexing
- Allows duplicate values
This topic forms the foundation for advanced data structures like stacks, queues, and matrices.