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

FlyFeditv

๐Ÿ“˜ Introduction In this project, youโ€™ll create a command-line Expense Tracker that allows users to: โœ… Add expenses with category, amount, and descriptionโœ… View total spending and category breakdownโœ… Automatically…

Read more

NetCinFly

๐Ÿ“˜ Introduction In this project, youโ€™ll develop a Student Grades Analyzer in Python that can: This project helps you strengthen your skills with lists, dictionaries, loops, and data analysis logic….

Read more

Eagle_Pro

๐ŸŒ Introduction In this project, youโ€™ll create a Web Scraper App in Python that extracts quotes, authors, and tags from a live website.Youโ€™ll use the BeautifulSoup and Requests libraries to…

Read more

Cobra_Pro

๐ŸŒฆ๏ธ Introduction In this project, youโ€™ll build a Weather App in Python that retrieves live weather information from an online API.Youโ€™ll learn how to work with HTTP requests, JSON data,…

Read more

Show7-Pro

Concepts Covered: ๐ŸŽฏ Objective: Create a simple, text-based contact book application that allows users to: ๐Ÿ’ก Code (contact_book.py): ๐Ÿง  Example Usage Console Output Example: ๐Ÿ’พ Notes โฌ‡๏ธ Download Show7-Pro ุชุญู…ูŠู„…

Read more

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