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

FivG_Pro

๐Ÿ”ฐ What Is a Function? A function is a reusable block of code that performs a specific task.Instead of repeating code, we can write it once and call it whenever…

Read more

Show7_Pro

๐ŸŸข Lesson 6 โ€“ Intermediate Level ๐Ÿ”ฐ What Is a Module? A module is simply a Python file (.py) containing code (functions, variables, classes) you can reuse in other programs….

Read more

GoldiptvPro

๐ŸŸข Lesson 5 โ€“ Intermediate Level ๐Ÿ”ฐ What Are Exceptions? An exception is an error that occurs during the execution of a program.If not handled, it will stop the program…

Read more

Domingo

๐ŸŸข Lesson 4 ๐Ÿ”ฐ What Is OOP? Object-Oriented Programming (OOP) is a programming style where you organize code into objects that contain: Python supports OOP using: ๐Ÿงฑ Example: Why Use…

Read more

SHARK_PRO

๐Ÿ”ฐ What Is File Handling? ๐ŸŸข Lesson 3 File handling lets your Python programs interact with files on your computer โ€” read data from them or save data to them….

Read more

ZinaTv

๐ŸŸข Lesson 2 โ€“ Intermediate Level ๐Ÿ”น Python Dictionaries: Storing and Accessing Key-Value Data ๐Ÿ”ฐ What Is a Dictionary? A dictionary in Python is a data structure that stores data…

Read more