A list is an ordered sequence data type that is mutable, meaning unlike strings, you can change, add, or remove items after the list has been created.
Indexing: Lists use zero-based indexing to access items.
Methods: Built-in functions like append(), insert(), remove(), and pop() let us modify list contents easily.
Strings and lists share a lot in common because both are sequence data types, meaning they are ordered collections where you can access items by index.
However, there is one major difference: Strings are immutable, meaning once you create a string, you cannot change, add, or remove characters in-place like you can with a list. Instead, you create new strings.
A string is an ordered sequence of characters. Just like lists, strings use zero-based indexing to access individual characters, but they do not allow direct modification of their contents.
A tuple is an ordered sequence data type, very similar to a list, with one major difference: tuples are immutable. Once a tuple is created, you cannot change, add, or remove its items.
Syntax: Tuples are defined using parentheses () instead of square brackets [].
Use Case: Tuples are used when data should remain constant (read-only) throughout your program, protecting it from accidental changes.
Scenario: You want to build a command-line task management tool that lets users organize their daily tasks.
Your program needs to:
Display a menu with options to View, Add, Modify, Delete, and Exit.
Keep the program running continuously using a while loop until the user chooses to exit.
Use Python's match-case statement to route the user's command to the correct feature.
Manage tasks using a list with methods like .append(), .insert(), and .pop()
Menu Explained
View (Option 1): Displays all current tasks in order using a for loop with enumerate().
Add (Option 2): Adds a task to the end using .append() or at a specific position using .insert().
Modify (Option 3): Updates an existing task using direct index assignment (tasks[index] = new_text).
Delete (Option 4): Removes a task from the list using .pop(index).
Exit (Option 5): Breaks out of the while loop to terminate the program gracefully.
Sample Output:
📝 Welcome to Your Interactive To-Do List Manager! 📝
=========================
MAIN MENU
=========================
1. View Tasks
2. Add Task
3. Modify Task
4. Delete Task
5. Exit
=========================
Enter your choice (1-5): 1
📭 Your to-do list is currently empty!
Enter your choice (1-5): 2
Enter the task description: Buy groceries
Do you want to add it at a specific position? (yes/no): no
✅ Task added successfully!
Enter your choice (1-5): 2
Enter the task description: Finish Python tutorial
Do you want to add it at a specific position? (yes/no): yes
Enter position number (1 to 2): 1
✅ Task inserted at position 1!
Enter your choice (1-5): 1
📋 Your Current Tasks:
1. Finish Python tutorial
2. Buy groceries
Enter your choice (1-5): 4
Current Tasks:
1. Finish Python tutorial
2. Buy groceries
Enter the task number you want to delete: 2
🗑️ Removed task: 'Buy groceries'
Enter your choice (1-5): 1
📋 Your Current Tasks:
1. Finish Python tutorial
Enter your choice (1-5): 5
👋 Goodbye! Stay productive and have a great day! 🚀
Write a Python program that stores a pre-defined list of color records.Each color record contains fixed information: a descriptive name and its exact RGB (Red, Green, Blue) code values.
Your task is to write a Python program that:
Stores each color using tuples (name, red, green, blue) because color values are fixed constants and should never be accidentally modified.
Collects multiple color tuples inside a list to form the complete brand palette.
Uses a for loop with for loop with enumerate() and tuple unpacking to neatly display each color's details.
Expected Output:
Brand Color Palette:
----------------------------------------
1: Emerald Green
Red: 46, Green: 139, Blue: 87
----------------------------------------
2: Sunset Orange
Red: 255, Green: 107, Blue: 107
----------------------------------------
3: Ocean Blue
Red: 78, Green: 205, Blue: 196
----------------------------------------