Showing posts with label beginner Python tutorial. Show all posts
Showing posts with label beginner Python tutorial. Show all posts

Monday, March 16, 2026

Lesson 6: Lists, Tuples, and Dictionaries | Coding Class Series

March 16, 2026 0



Lesson 6: Lists, Tuples, and Dictionaries | Coding Class Series

Introduction

Welcome to Lesson 6!
In this lesson, we will learn about Python data structures: lists, tuples, and dictionaries. These structures help you store and organize multiple values efficiently.


1. Lists

A list is an ordered and mutable collection of items.
You can add, remove, or change elements in a list.

Syntax:

fruits = ["apple", "banana", "cherry"]
print(fruits[0])  # Access first item

Common List Methods:

fruits.append("orange")     # Add item
fruits.remove("banana")     # Remove item
fruits.sort()               # Sort items
print(fruits)

2. Tuples

A tuple is ordered but immutable.
Once created, you cannot change its elements.

Syntax:

coordinates = (10, 20)
print(coordinates[0])

Why use tuples?

  • They are faster than lists
  • Useful for data that should not change, like coordinates or constants.

3. Dictionaries

A dictionary stores key-value pairs.
You can access values using keys, not indexes.

Syntax:

student = {"name": "Alice", "age": 16, "grade": "A"}
print(student["name"])  # Output: Alice

Common Dictionary Methods:

student["age"] = 17        # Update value
student["city"] = "Delhi"  # Add new key-value pair
print(student.keys())      # Show all keys
print(student.values())    # Show all values

Practice Exercises

  1. Create a list of your 5 favorite movies. Print them in alphabetical order.
  2. Create a tuple of your 3 favorite colors and try to change one color (observe what happens).
  3. Create a dictionary for a book: title, author, year. Update the year and print all keys and values.
  4. Use a list of dictionaries to store 3 students’ information and print each student’s name and grade.


Lesson 3: Conditional Statements and Loops | Coding Class Series

March 16, 2026 0

 

Lesson 3: Conditional Statements and Loops | Coding Class Series

Welcome to Lesson 3 of our Coding Class Series! In this lesson, we will learn how to make decisions in code using conditional statements and how to repeat tasks using loops. These are essential concepts in every programming language.

Conditional Statements (if-else)

Conditional statements help your program make decisions based on certain conditions.

# Example in Python
age = 18
if age >= 18:
    print("You are an adult")
else:
    print("You are a minor")

Explanation:

  • If the condition age >= 18 is True, the first block of code executes.
  • If it is False, the code inside else executes.

Loops

Loops are used to repeat a block of code multiple times.

For Loop

# Print numbers from 0 to 4
for i in range(5):
    print(i)

While Loop

count = 0
while count < 5:
    print(count)
    count += 1

Practice Exercises

  1. Write a program to check if a number is even or odd.
  2. Print numbers from 1 to 10 using a loop.
  3. Create a loop that sums all numbers from 1 to 100.
  4. Write a program to print only the numbers divisible by 3 between 1 and 50.