Python Lists

1. What is a List?

A list is a collection of many values stored in one variable.

In simple words:
👉 A list is like a box that can hold many items.

Example

fruits = ["apple", "banana", "orange"]
print(fruits)

2. Why Use Lists?

Lists help us:

  • Store many values together

  • Access items easily

  • Change items when needed

3. Creating a List

Lists are written using square brackets [ ].

Example

numbers = [10, 20, 30, 40]
names = ["Amit", "Ravi", "Sita"]

4. Accessing List Items (Index)

Each item in a list has a position number (index).

Index starts from 0.

Example

fruits = ["apple", "banana", "orange"]

print(fruits[0]) # apple
print(fruits[1]) # banana
print(fruits[2]) # orange

5. Negative Indexing

Negative index starts from the end.

Example

print(fruits[-1]) # orange
print(fruits[-2]) # banana

6. Changing List Items

Lists are changeable (mutable).

Example

fruits[1] = "mango"
print(fruits)

7. List Length

Use len() to find how many items are in the list.

Example

print(len(fruits))

8. Adding Items to a List

Using append() (Add at end)

fruits.append("grape")
print(fruits)

Using insert() (Add at position)

fruits.insert(1, "kiwi")
print(fruits)

9. Removing Items from a List

Using remove()

fruits.remove("apple")
print(fruits)

Using pop()

fruits.pop()
print(fruits)

10. Loop Through a List

Example

for fruit in fruits:
print(fruit)

11. Checking Item in List

Example

print("banana" in fruits)

12. Common Beginner Mistakes

❌ Wrong Index

print(fruits[5])

❌ Error: index out of range.

❌ Forgetting Quotes

fruits = [apple, banana]

✔ Correct:

fruits = ["apple", "banana"]

13. Simple Practice Examples

Example 1: Number List

numbers = [1, 2, 3, 4]
print(numbers)

Example 2: Sum of List

numbers = [10, 20, 30]
print(sum(numbers))

Example 3: Change Item

colors = ["red", "blue", "green"]
colors[0] = "yellow"
print(colors)

14. Summary (Python Lists)

✔ Lists store many values
✔ Index starts from 0
✔ Lists are changeable
✔ Use append(), insert(), remove()
✔ Very useful in real programs

📘 Perfect for Beginner eBook

This chapter is ideal for:

  • Python beginner books

  • School & college students

  • Self-learners

If you want next, I can write:

  • List Methods (in detail)

  • List Exercises

  • Tuples

  • Sets

  • Dictionaries

Just tell me 😊

You may also like...