Akratv

Lesson 7 – Functions and Scope in Python

📘 Introduction

The current image has no alternative text. The file name is: aKIRA.jpg

In Python, lists, tuples, and sets are three important ways to store collections of items. Each has unique features and is used in different scenarios.
Understanding these structures is crucial for managing data effectively.


🔹 1. Lists in Python

  • A list is an ordered collection that can hold multiple items.
  • Lists are mutable (you can change them after creation).

Example:

fruits = ["apple", "banana", "cherry"]
print(fruits)         # ['apple', 'banana', 'cherry']

# Adding an item
fruits.append("orange")
print(fruits)         # ['apple', 'banana', 'cherry', 'orange']

# Changing an item
fruits[1] = "mango"
print(fruits)         # ['apple', 'mango', 'cherry', 'orange']

🔹 2. Tuples in Python

  • A tuple is an ordered collection like a list, but it is immutable (cannot be changed after creation).
  • Use tuples when you want data to stay constant.

Example:

colors = ("red", "green", "blue")
print(colors)         # ('red', 'green', 'blue')

# Trying to change a value will cause an error
# colors[0] = "yellow" ❌ Not allowed

🔹 3. Sets in Python

  • A set is an unordered collection of unique items.
  • Sets automatically remove duplicates.

Example:

numbers = {1, 2, 3, 3, 4, 5}
print(numbers)        # {1, 2, 3, 4, 5}

# Adding items
numbers.add(6)
print(numbers)        # {1, 2, 3, 4, 5, 6}

# Removing items
numbers.remove(3)
print(numbers)        # {1, 2, 4, 5, 6}

🔹 4. Key Differences

FeatureListTupleSet
Ordered✅ Yes✅ Yes❌ No
Mutable✅ Yes❌ No✅ Yes
Duplicates✅ Allowed✅ Allowed❌ Not Allowed
Use CaseGeneral collectionsFixed dataUnique items collection

✅ Summary

  • Lists are flexible, ordered, and changeable.
  • Tuples are ordered but fixed (immutable).
  • Sets are unordered and unique.

⬇️ Download Akratvتحميل ⬇️ Download Akratv تحميل Server 2 ⬇️ Download Akratv تحميل Server 3

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