What is List in Python? Definition, Syntax and Examples
A list in Python is an ordered, mutable collection that can store different data types. Learn creation, indexing, common methods and examples.
What is a list?
Definition: A list in Python is an ordered, mutable (changeable) collection that can store any number of items of any data type — numbers, strings, even other lists — inside square brackets
[ ].marks = [85, 92, 78, 90] # integers
names = ["Aman", "Priya", "Rahul"] # strings
mixed = [101, "Gagan", 95.5, True] # mixed types allowed
nested = [[1, 2], [3, 4]] # list inside list
empty = [] # empty list
3 key properties (remember for exams)
- Ordered: items keep their position —
marks[0]is always 85 until you change it. - Mutable: you can add, remove or change items after creation.
- Allows duplicates:
[5, 5, 5]is a valid list with 3 items.
Accessing items: indexing and slicing
fruits = ["apple", "banana", "mango", "grape"]
print(fruits[0]) # apple (first item, index starts at 0)
print(fruits[-1]) # grape (negative index = from the end)
print(fruits[1:3]) # ['banana', 'mango'] (slice: index 1 to 2)
print(len(fruits)) # 4
apple
grape
['banana', 'mango']
4
Most used list methods
nums = [10, 20, 30]
nums.append(40) # [10, 20, 30, 40] add at end
nums.insert(1, 15) # [10, 15, 20, 30, 40] add at index 1
nums.remove(20) # [10, 15, 30, 40] remove by value
last = nums.pop() # [10, 15, 30] remove & return last
nums.sort() # ascending sort
nums.reverse() # reverse order
print(nums)
[30, 15, 10]
| Method | Work |
|---|---|
append(x) | Add one item at the end |
insert(i, x) | Add item at index i |
remove(x) | Delete first occurrence of value x |
pop(i) | Remove and return item at index i (default last) |
sort() / reverse() | Sort ascending / reverse in place |
count(x) / index(x) | Count occurrences / find first index |
Looping through a list
students = ["Aman", "Priya", "Rahul"]
for s in students:
print("Hello", s)
for i, s in enumerate(students, start=1):
print(i, s)
Hello Aman
Hello Priya
Hello Rahul
1 Aman
2 Priya
3 Rahul
List क्या है?
Definition: Python में list एक ordered, mutable (बदली जा सकने वाली) collection है जो square brackets
[ ] में किसी भी data type के कितने भी items store कर सकती है — numbers, strings, यहां तक कि दूसरी lists भी.marks = [85, 92, 78, 90] # integers
names = ["Aman", "Priya", "Rahul"] # strings
mixed = [101, "Gagan", 95.5, True] # mixed types allowed
nested = [[1, 2], [3, 4]] # list के अंदर list
empty = [] # खाली list
3 key properties (exams के लिए याद रखें)
- Ordered: items अपनी position रखते हैं —
marks[0]हमेशा 85 रहेगा जब तक आप बदलें नहीं. - Mutable: बनाने के बाद items add, remove या change कर सकते हैं.
- Duplicates allowed:
[5, 5, 5]3 items वाली valid list है.
Items access करना: Indexing और Slicing
fruits = ["apple", "banana", "mango", "grape"]
print(fruits[0]) # apple (पहला item, index 0 से शुरू)
print(fruits[-1]) # grape (negative index = अंत से)
print(fruits[1:3]) # ['banana', 'mango'] (slice: index 1 से 2)
print(len(fruits)) # 4
apple
grape
['banana', 'mango']
4
सबसे ज़्यादा use होने वाले list methods
nums = [10, 20, 30]
nums.append(40) # [10, 20, 30, 40] अंत में add
nums.insert(1, 15) # [10, 15, 20, 30, 40] index 1 पर add
nums.remove(20) # [10, 15, 30, 40] value से remove
last = nums.pop() # [10, 15, 30] last remove & return
nums.sort() # ascending sort
nums.reverse() # order उलटें
print(nums)
[30, 15, 10]
| Method | काम |
|---|---|
append(x) | अंत में एक item जोड़ें |
insert(i, x) | Index i पर item जोड़ें |
remove(x) | Value x की पहली occurrence delete करें |
pop(i) | Index i का item remove करके return करें (default last) |
sort() / reverse() | Ascending sort / in-place reverse |
count(x) / index(x) | Occurrences गिनें / पहला index खोजें |
List में loop चलाना
students = ["Aman", "Priya", "Rahul"]
for s in students:
print("Hello", s)
for i, s in enumerate(students, start=1):
print(i, s)
Hello Aman
Hello Priya
Hello Rahul
1 Aman
2 Priya
3 Rahul
Frequently Asked Questions
What is a list in Python in one line?
A list is an ordered, mutable collection of items of any data type, written inside square brackets like [1, "two", 3.0].
Can a Python list store different data types?
Yes. A single list can mix integers, strings, floats, booleans and even other lists: [101, "Gagan", 95.5, True].
What is the difference between append and insert?
append(x) always adds the item at the end of the list, while insert(i, x) adds the item at any index i you choose.