Welcome to Python World!

Learn Coding Step by Step 🚀

A fun beginner programming course for young programmers
Created by Geta Ba / GETCOM

📝 Example 31: Create and Display Lists

Python stores multiple values in a list.

🐍 Python Code



# EXAMPLE 31
# Create and Display Lists

n = [2, 4, 6, 8, 10]

s = ["Gech", "Abebe", "Saba"]

print("Number List =", n)

print("Student List =", s)

🤖 Python Output

Number List = [2, 4, 6, 8, 10]

Student List = ['Gech', 'Abebe', 'Saba']

⭐ Challenge: Create your own number list and name list.

👀 Example 32: Access List Elements

Python can access any item in a list using its index.

🐍 Python Code



# EXAMPLE 32

n = [2, 4, 6, 8, 10]

s = ["Gech", "Abebe", "Saba"]

print("First Number =", n[0])

print("Last Number =", n[-1])

print("First Student =", s[0])

print("Last Student =", s[-1])

🤖 Python Output

First Number = 2

Last Number = 10

First Student = Gech

Last Student = Saba

⭐ Challenge: Print the second number and the second student.

➕ Example 33: Add Items Using append()

The append() function adds a new item to the end of a list.

🐍 Python Code



# EXAMPLE 33

n = [2, 4, 6, 8, 10]

s = ["Gech", "Abebe", "Saba"]

n.append(12)

s.append("Meron")

print("Numbers =", n)

print("Students =", s)

🤖 Python Output

Numbers = [2, 4, 6, 8, 10, 12]

Students = ['Gech', 'Abebe', 'Saba', 'Meron']

⭐ Challenge: Add another number and another student.

📌 Example 34: Insert Items into a List

The insert() function adds an item at a specific position.

🐍 Python Code



# EXAMPLE 34

n = [2, 4, 6, 8, 10]

s = ["Gech", "Abebe", "Saba"]

n.insert(2, 5)

s.insert(1, "Hanna")

print("Numbers =", n)

print("Students =", s)

🤖 Python Output

Numbers = [2, 4, 5, 6, 8, 10]

Students = ['Gech', 'Hanna', 'Abebe', 'Saba']

⭐ Challenge: Insert a new student at the beginning of the list.

❌ Example 35: Remove Items from a List

The remove() function deletes an item by its value.

🐍 Python Code



# EXAMPLE 35

n = [2, 4, 6, 8, 10]

s = ["Gech", "Abebe", "Saba"]

n.remove(6)

s.remove("Abebe")

print("Numbers =", n)

print("Students =", s)

🤖 Python Output

Numbers = [2, 4, 8, 10]

Students = ['Gech', 'Saba']

⭐ Challenge: Remove the first number and the last student from the lists.

🗑️ Example 36: Delete an Item Using del

The del statement removes an item by its index.

🐍 Python Code



# EXAMPLE 36

n = [2, 4, 6, 8, 10]

s = ["Gech", "Abebe", "Saba"]

del n[2]

del s[1]

print("Numbers =", n)

print("Students =", s)

🤖 Python Output

Numbers = [2, 4, 8, 10]

Students = ['Gech', 'Saba']

⭐ Challenge: Delete the first number and the last student.

📤 Example 37: Remove the Last Item Using pop()

The pop() function removes and returns the last item.

🐍 Python Code



# EXAMPLE 37

n = [2, 4, 6, 8, 10]

s = ["Gech", "Abebe", "Saba"]

number = n.pop()

student = s.pop()

print("Removed Number =", number)

print("Removed Student =", student)

print("Numbers =", n)

print("Students =", s)

🤖 Python Output

Removed Number = 10

Removed Student = Saba


Numbers = [2, 4, 6, 8]

Students = ['Gech', 'Abebe']

⭐ Challenge: Use pop(1) to remove the second item.

📏 Example 38: Find the Length of a List

The len() function counts the number of items.

🐍 Python Code



# EXAMPLE 38

n = [2, 4, 6, 8, 10]

s = ["Gech", "Abebe", "Saba"]

print("Total Numbers =", len(n))

print("Total Students =", len(s))

🤖 Python Output

Total Numbers = 5

Total Students = 3

⭐ Challenge: Create a list of 10 numbers and display its length.

🔃 Example 39: Sort a List

The sort() function arranges items in ascending order.

🐍 Python Code



# EXAMPLE 39

n = [10, 6, 2, 8, 4]

s = ["Saba", "Gech", "Abebe"]

n.sort()

s.sort()

print("Numbers =", n)

print("Students =", s)

🤖 Python Output

Numbers = [2, 4, 6, 8, 10]

Students = ['Abebe', 'Gech', 'Saba']

⭐ Challenge: Sort your own list of names alphabetically.

🔄 Example 40: Reverse a List

The reverse() function changes the order of items.

🐍 Python Code



# EXAMPLE 40

n = [2, 4, 6, 8, 10]

s = ["Gech", "Abebe", "Saba"]

n.reverse()

s.reverse()

print("Numbers =", n)

print("Students =", s)

🤖 Python Output

Numbers = [10, 8, 6, 4, 2]

Students = ['Saba', 'Abebe', 'Gech']

⭐ Challenge: Reverse a list of your favorite colors.

📈 Example 41: Find Maximum and Minimum Values

Python uses max() and min() to find the largest and smallest values.

🐍 Python Code



# EXAMPLE 41
# Maximum and Minimum


n = [2, 4, 6, 8, 10]


print("Maximum =", max(n))

print("Minimum =", min(n))


🤖 Python Output

Maximum = 10

Minimum = 2

⭐ Challenge: Create a list of marks and find the highest and lowest mark.

➕ Example 42: Calculate Sum of a List

The sum() function adds all numbers in a list.

🐍 Python Code



# EXAMPLE 42
# Sum of List


n = [2, 4, 6, 8, 10]


total = sum(n)


print("Total Sum =", total)


🤖 Python Output

Total Sum = 30

⭐ Challenge: Calculate the sum of numbers from 1 to 100.

🔍 Example 43: Search an Item in a List

Python checks whether an item exists using the in operator.

🐍 Python Code



# EXAMPLE 43
# Search Student Name


s = ["Gech", "Abebe", "Saba"]


name = input("Enter Student Name: ")


if name in s:

    print("Student Found")

else:

    print("Student Not Found")


🤖 Python Output

Enter Student Name: Gech


Student Found ✅

⭐ Challenge: Search for "Abebe" and "Mulu".

🔢 Example 44: Count Items in a List

The count() function counts repeated values.

🐍 Python Code



# EXAMPLE 44
# Count Occurrence


n = [2, 4, 6, 4, 8, 4, 10]


number = 4


print("Count =", n.count(number))


🤖 Python Output

Count = 3

⭐ Challenge: Count how many times your favorite number appears.

📋 Example 45: Copy a List

The copy() function creates a new copy of a list.

🐍 Python Code



# EXAMPLE 45
# Copy List


n = [2, 4, 6, 8, 10]


new_list = n.copy()


print("Original List =", n)


print("Copied List =", new_list)


🤖 Python Output

Original List = [2, 4, 6, 8, 10]

Copied List = [2, 4, 6, 8, 10]

⭐ Challenge: Copy the student list and add a new student.

🔗 Example 46: Combine Two Lists

Python combines two lists using the + operator.

🐍 Python Code



# EXAMPLE 46
# Combine Two Lists


n = [2, 4, 6, 8, 10]

s = ["Gech", "Abebe", "Saba"]


combined = n + s


print("Combined List:")

print(combined)


🤖 Python Output

[2, 4, 6, 8, 10, 'Gech', 'Abebe', 'Saba']

⭐ Challenge: Create two new lists and combine them.

🔁 Example 47: Loop Through a List

Python uses a for loop to display every item in a list.

🐍 Python Code



# EXAMPLE 47
# Loop Through Student List


s = ["Gech", "Abebe", "Saba"]


print("Student Names:")


for student in s:

    print(student)


🤖 Python Output

Student Names:


Gech

Abebe

Saba

⭐ Challenge: Add two more students and display all names.

🎓 Example 48: Student Marks List

Python stores marks in a list and calculates the average.

🐍 Python Code



# EXAMPLE 48
# Student Marks


n = [2, 4, 6, 8, 10]


total = sum(n)


average = total / len(n)


print("Marks =", n)

print("Total =", total)

print("Average =", average)


🤖 Python Output

Marks = [2, 4, 6, 8, 10]


Total = 30

Average = 6.0

⭐ Challenge: Change the marks and calculate a new average.

2️⃣ Example 49: Find Even Numbers from a List

Python checks each number and displays only even numbers.

🐍 Python Code



# EXAMPLE 49
# Even Numbers


n = [2, 4, 6, 8, 10]


print("Even Numbers:")


for number in n:


    if number % 2 == 0:

        print(number)


🤖 Python Output

Even Numbers:


2

4

6

8

10

⭐ Challenge: Create a list with odd and even numbers and display only even numbers.

👨‍🎓 Example 50: Simple Student Registration System

Python uses lists to store multiple student names.

🐍 Python Code



# EXAMPLE 50
# Student Registration System


s = []


while True:


    print("\n1. Add Student")

    print("2. Display Students")

    print("3. Exit")



    choice = input("Enter Choice: ")




    if choice == "1":


        name = input("Enter Student Name: ")

        s.append(name)

        print("Student Added Successfully")




    elif choice == "2":


        print("\nStudent List:")


        for student in s:

            print(student)




    elif choice == "3":


        print("Program Ended")

        break




    else:

        print("Invalid Choice")


🤖 Python Output

1. Add Student

2. Display Students

3. Exit


Enter Choice: 1

Enter Student Name: Gech

Student Added Successfully ✅

🚀 Project: Create a student system that can add, search, and delete students.