Python – Access List Items

1. What Does β€œAccess List Items” Mean?

Accessing list items means getting values from a list.

In simple words:
πŸ‘‰ It means reading items from the list.

2. List Index (Position)

Each item in a list has a position number called index.

Important rules:

  • Index starts from 0

  • First item β†’ index 0

  • Second item β†’ index 1

Example

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

print(fruits[0])
print(fruits[1])
print(fruits[2])

Output:

apple
banana
orange

3. Access Item Using Index

Example

colors = ["red", "blue", "green"]

print(colors[1])

Output:

blue

4. Negative Indexing

Negative index means counting from the end of the list.

  • -1 β†’ last item

  • -2 β†’ second last item

Example

animals = ["cat", "dog", "cow"]

print(animals[-1])
print(animals[-2])

Output:

cow
dog

5. Access a Range of Items (Slicing)

Slicing means getting more than one item.

Example

numbers = [10, 20, 30, 40, 50]

print(numbers[1:4])

Output:

[20, 30, 40]

πŸ‘‰ End index is not included.

6. Access From Beginning

Example

print(numbers[:3])

Output:

[10, 20, 30]

7. Access Till End

Example

print(numbers[2:])

Output:

[30, 40, 50]

8. Check if Item Exists

Example

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

if "banana" in fruits:
print("Banana is in the list")

9. Access Items Using Loop

Example

for fruit in fruits:
print(fruit)

10. Common Beginner Mistakes

❌ Index Out of Range

print(fruits[5])

βœ” Fix:

print(len(fruits))

❌ Wrong Index Expectation

print(fruits[1]) # expecting apple

βœ” Correct:

print(fruits[0])

11. Simple Practice Examples

Example 1: Print First and Last Item

numbers = [5, 10, 15, 20]

print(numbers[0])
print(numbers[-1])

Example 2: Slice List

marks = [60, 70, 80, 90, 100]
print(marks[1:4])

Example 3: Check Name

names = ["Amit", "Ravi", "Sita"]

print("Ravi" in names)

12. Summary (Access List Items)

βœ” Use index to access items
βœ” Index starts from 0
βœ” Negative index counts from end
βœ” Slicing gives multiple items
βœ” in checks item existence

πŸ“˜ Perfect for Beginner eBook

This chapter is ideal for:

  • Python beginner books

  • School & college students

  • Self-learners

If you want next, I can write:

  • Change List Items

  • Add List Items

  • Remove List Items

  • List Methods

  • List Exercises

Just tell me 😊

You may also like...