Pro_Click

๐Ÿ”ฐ What Are Lists ?

The current image has no alternative text. The file name is: IMG_20250727_025455_edit_203788372652756-scaled.jpg

A list is an ordered collection of items stored in a single variable.

๐Ÿ“Œ Lists are defined using square brackets [].

๐Ÿงช Example :

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

๐Ÿ“ค Output:

cssCopierModifier['apple', 'banana', 'orange']

๐Ÿงฉ Key Properties of Lists:

  • โœ… Lists can store different types of data (strings, numbers, etc.).
  • โœ… They are mutable (you can change the content).
  • โœ… Support looping, updating, and searching.

๐Ÿ“ฅ Adding Items to a List

pythonCopierModifierfruits.append("grapes")
print(fruits)

๐ŸŸข append() adds an item to the end of the list.


โŒ Removing an Item from the List

pythonCopierModifierfruits.remove("banana")
print(fruits)

๐Ÿ“Œ If the item is not found, it raises an error.


๐Ÿ—‚๏ธ Accessing List Elements:

โœ… Using indexing:

pythonCopierModifierprint(fruits[0])   # First item
print(fruits[-1])  # Last item

๐Ÿ” Looping Through a List:

pythonCopierModifierfor fruit in fruits:
    print("I like", fruit)

๐Ÿ”ƒ Sorting a List:

pythonCopierModifiernumbers = [5, 1, 9, 3]
numbers.sort()
print(numbers)  # [1, 3, 5, 9]

๐Ÿง  Exercise 1:

Write a program that:

  • Creates an empty list.
  • Asks the user to enter 3 friend names.
  • Adds them to the list.
  • Prints the final list.
pythonCopierModifierfriends = []

for i in range(3):
    name = input("Enter a friend's name: ")
    friends.append(name)

print("๐Ÿ“‹ Your friends are:", friends)

๐Ÿ”„ Useful List Functions:

FunctionPurpose
append(x)Add item x to the end
remove(x)Remove item x by value
pop(i)Remove item at index i
sort()Sort list in ascending order
reverse()Reverse the list order
len(list)Get the number of elements
list.clear()Remove all elements

๐Ÿ” Searching in a List:

pythonCopierModifierif "banana" in fruits:
    print("๐ŸŒ Banana is in the list!")
else:
    print("Banana is not found.")

๐Ÿง  Exercise 2 (Intermediate):

Write a program that:

  • Asks the user to enter numbers until they type “exit”.
  • Stores them in a list.
  • Calculates the sum and average.
  • Prints the total number of entries.
pythonCopierModifiernumbers = []

while True:
    entry = input("Enter a number (or type 'exit' to finish): ")
    if entry.lower() == "exit":
        break
    try:
        num = float(entry)
        numbers.append(num)
    except:
        print("โš ๏ธ Please enter a valid number.")

if numbers:
    print("๐Ÿ“Š Count:", len(numbers))
    print("๐Ÿ”ข Sum:", sum(numbers))
    print("๐Ÿ“ˆ Average:", sum(numbers) / len(numbers))
else:
    print("No numbers were entered.")

๐Ÿ“ Summary:

  • Lists are powerful for managing collections of data.
  • You can add, remove, sort, reverse, and search items easily.
  • Lists are used everywhere in real-world Python programs.

Code Activate ูƒูˆุฏ ุงู„ุชูุนูŠู„

User: MohammedYaseenTayeb
Pass: 66259927
User: AlobaidiAlhamadi
Pass: 86129517
User: MuhammadMahmod
Pass: 63944489
User: TarekShiekhHamoud
Pass: 62855174

โฌ‡๏ธ Download Pro_Click ุชุญู…ูŠู„ Server 1 โฌ‡๏ธ Download Pro_Click ุชุญู…ูŠู„ Server 2

Related Posts

Rapid_tv

๐Ÿ”น Introduction The Rock, Paper, Scissors Game is a classic hand game that you can easily build in Python. ๐Ÿ‘‰ Rules: ๐Ÿ”น Code Example ๐Ÿ”น Example Run ๐Ÿ”น Concepts Learned…

Read more

VOD-ZalHD

๐Ÿ”น Introduction The Number Guessing Game is a classic beginner Python project. ๐Ÿ”น Code Example ๐Ÿ”น Example Run ๐Ÿ”น Concepts Learned ๐Ÿ”น Summary โฌ‡๏ธ Download VOD-ZalHD ุชุญู…ูŠู„ Server 1 โฌ‡๏ธ…

Read more

Delux_pro

๐Ÿ”น Introduction The To-Do List App is one of the most popular beginner projects. It teaches you how to: ๐Ÿ”น Code Example ๐Ÿ”น Features of This App ๐Ÿ”น Example Run…

Read more

Fam4k

๐Ÿ”ฐ Project Overview A calculator is one of the simplest yet most effective projects to start with in Python.You will learn: โœ๏ธ Step 1: Plan the Calculator We need: ๐Ÿ–ฅ๏ธ…

Read more

Speed_HD+

1. Introduction Data visualization helps us understand patterns and insights in data by converting raw numbers into charts and graphs.In Python, the most popular libraries are: 2. Installing Required Libraries…

Read more

Dauo

1. Introduction Web scraping is the process of extracting data from websites. In Python, we commonly use libraries like requests (to fetch web pages) and BeautifulSoup (to parse and extract…

Read more