Learn Coding
57 subscribers
21 links
Download Telegram
🚨 Video Reference

Watch this after reading through all the posts

Python Full Course 2024 — freeCodeCamp

🔖 Watch from 2:59:18 → 3:31:22
Covers lists, for loops with lists, and string concatenation
Please open Telegram to view this post
VIEW IN TELEGRAM
✏️ Lecture 6 Homework

Build a simple to-do list program:

todos = []

todos.append("Learn Python")
todos.append("Build a Telegram bot")
todos.append("Deploy my first project")

print("Your To-Do List:")
for index, task in enumerate(todos):
print(f"{index + 1}. {task}")

print(f"Total tasks: {len(todos)}")


Then extend it — ask the user to add their own tasks using input() in a loop
Stop when they type "done"
Then print the full list
Screenshot your output

Bonus — let the user also delete a task by number

⚠️ Next lecture drops tomorrow — Dictionaries & Sets
Please open Telegram to view this post
VIEW IN TELEGRAM
This media is not supported in your browser
VIEW IN TELEGRAM
Premium khatam💔
📚 𝗟𝗲𝗰𝘁𝘂𝗿𝗲 𝟳 — 𝗗𝗶𝗰𝘁𝗶𝗼𝗻𝗮𝗿𝗶𝗲𝘀 & 𝗦𝗲𝘁𝘀

Lists store items by position — index 0, 1, 2...
But sometimes you need to store data by name
Like a real dictionary — look up a word, get its meaning
That is exactly what Python dictionaries do

This lecture covers:
➡️ What dictionaries are and how to create them
➡️ Accessing, adding, updating, and deleting
➡️ Looping through dictionaries
➡️ Nested dictionaries
➡️ Sets — and when to use them
Please open Telegram to view this post
VIEW IN TELEGRAM
📌 What is a Dictionary?

A dictionary stores data as key-value pairs
Instead of an index number you use a key — a name you choose

user = {
"name": "Ahmed",
"age": 22,
"city": "Dubai",
"is_admin": False
}


Accessing values by key:
print(user["name"])    # Ahmed
print(user["age"]) # 22


Safer way using .get() — returns None instead of crashing if key does not exist:
print(user.get("email"))           # None
print(user.get("email", "N/A")) # N/A — default value
Please open Telegram to view this post
VIEW IN TELEGRAM
📌 Adding, Updating, and Deleting

Adding a new key:
user["email"] = "ahmed@gmail.com"


Updating an existing key:
user["age"] = 23


Deleting a key:
del user["city"]
user.pop("is_admin")


Checking if a key exists:
if "email" in user:
print("Has email")

print(len(user)) # number of keys
Please open Telegram to view this post
VIEW IN TELEGRAM
📌Looping Through Dictionaries

user = {"name": "Ahmed", "age": 22, "city": "Dubai"}

# loop through keys only
for key in user:
print(key)

# loop through values only
for value in user.values():
print(value)

# loop through both — most useful
for key, value in user.items():
print(f"{key}: {value}")


Output of last loop:
name: Ahmed
age: 22
city: Dubai
Please open Telegram to view this post
VIEW IN TELEGRAM
📌 Nested Dictionaries

Dictionaries can contain other dictionaries
This is how real user data is usually structured

users = {
"ahmed": {
"age": 22,
"is_admin": True
},
"sara": {
"age": 19,
"is_admin": False
}
}

print(users["ahmed"]["age"]) # 22
print(users["sara"]["is_admin"]) # False


You will see this exact pattern constantly when working with APIs and bots
Telegram sends you user data in this format
Please open Telegram to view this post
VIEW IN TELEGRAM
📌 Sets

A set is like a list but:
➡️ No duplicates allowed — automatically removed
➡️ No order — no indexes

tags = {"python", "bots", "coding", "python"}  # duplicate python
print(tags) # {'python', 'bots', 'coding'} — duplicate removed


Most common use case — removing duplicates from a list:
numbers = [1, 2, 2, 3, 3, 3, 4]
unique = list(set(numbers))
print(unique) # [1, 2, 3, 4]


Checking membership is also faster with sets than lists
Use sets when you need unique items and do not care about order
Please open Telegram to view this post
VIEW IN TELEGRAM
🚨 Video Reference

Watch this after reading through all the posts

Python Full Course 2024 — freeCodeCamp

🔖 Watch from 3:31:22 → 3:57:50
Covers dictionaries, iterating over dictionaries, and associating values
Please open Telegram to view this post
VIEW IN TELEGRAM
✏️ Lecture 7 Homework

Build a simple contacts manager using a dictionary:

contacts = {
"Ahmed": "050-1234567",
"Sara": "055-7654321",
"Ali": "052-1112233"
}

# print all contacts
for name, number in contacts.items():
print(f"{name}: {number}")

# search for a contact
search = input("Search name: ").strip().title()
if search in contacts:
print(f"Number: {contacts[search]}")
else:
print("Contact not found")


Extend it — let the user add a new contact and delete one
Screenshot your output

Bonus — store each contact as a nested dict with number and email

⚠️ Next lecture drops in 2 days — Functions
Please open Telegram to view this post
VIEW IN TELEGRAM
This media is not supported in your browser
VIEW IN TELEGRAM
Will upload lecture 8 today in evening
📚 𝗟𝗲𝗰𝘁𝘂𝗿𝗲 𝟴 — 𝗙𝘂𝗻𝗰𝘁𝗶𝗼𝗻𝘀

You have been writing code that runs top to bottom
But what happens when you need to do the same thing in 10 different places?
You do not copy paste it 10 times
You put it in a function and call it whenever you need it

Functions are one of the most important concepts in programming
Everything in real code is built with functions

This lecture covers:
➡️ Creating and calling functions
➡️ Parameters and arguments
➡️ Return values
➡️ Default parameters
➡️ *args and **kwargs
Please open Telegram to view this post
VIEW IN TELEGRAM
📌 Creating and Calling Functions

You create a function with the def keyword:

def greet():
print("Hello! Welcome to the channel")


Nothing happens yet — you need to call it:
greet()   # Hello! Welcome to the channel
greet() # Hello! Welcome to the channel
greet() # Hello! Welcome to the channel


One function, called 3 times
If you need to change the message you change it in one place — not 3
This is the power of functions
Please open Telegram to view this post
VIEW IN TELEGRAM
📌 Parameters and Arguments

Parameters let you pass data into a function:

def greet(name):
print(f"Hello {name}!")

greet("Ahmed") # Hello Ahmed!
greet("Sara") # Hello Sara!
greet("Ali") # Hello Ali!


Multiple parameters:
def introduce(name, age, city):
print(f"My name is {name}, I am {age} years old and from {city}")

introduce("Ahmed", 22, "Dubai")


Parameter = the variable in the function definition
Argument = the actual value you pass when calling it
People use these words interchangeably — do not stress about it
Please open Telegram to view this post
VIEW IN TELEGRAM
📌 Return Values

Functions can also give something back using return

def add(a, b):
return a + b

result = add(10, 5)
print(result) # 15


Without return your function does something but gives nothing back
With return your function produces a value you can use elsewhere

def is_adult(age):
if age >= 18:
return True
return False

if is_adult(20):
print("Access granted")
else:
print("Access denied")


Return also stops the function immediately
Any code after return does not run
Please open Telegram to view this post
VIEW IN TELEGRAM
📌 Default Parameters

You can give parameters a default value
If nothing is passed — it uses the default

def greet(name, message="Welcome back"):
print(f"Hello {name}! {message}")

greet("Ahmed") # Hello Ahmed! Welcome back
greet("Sara", "You are now banned") # Hello Sara! You are now banned


Default parameters must always come after non-default ones

You will use this constantly in bot handlers
For example a send_message function where parse_mode defaults to HTML
Please open Telegram to view this post
VIEW IN TELEGRAM
📌 *args and **kwargs

Sometimes you do not know how many arguments will be passed

*args — accepts any number of positional arguments as a tuple:
def add_all(*numbers):
return sum(numbers)

print(add_all(1, 2, 3)) # 6
print(add_all(1, 2, 3, 4, 5)) # 15


**kwargs — accepts any number of keyword arguments as a dictionary:
def show_info(**details):
for key, value in details.items():
print(f"{key}: {value}")

show_info(name="Ahmed", age=22, city="Dubai")


You do not need to memorize these right now
Just know they exist — you will see them when reading library code
Please open Telegram to view this post
VIEW IN TELEGRAM