Learn Coding
56 subscribers
21 links
Download Telegram
🚨 Video Reference

Watch this after reading through all the posts

Python Full Course 2024 — freeCodeCamp

🔖 Watch from 6:56:46 → 8:26:54
Covers file I/O, appending, with keyword, reading files, CSV files, and binary files
Please open Telegram to view this post
VIEW IN TELEGRAM
✏️ Lecture 11 Homework

Build a persistent to-do list — one that saves and loads from a file:

import json
import os

FILENAME = "todos.json"

def load_todos():
if os.path.exists(FILENAME):
with open(FILENAME, "r") as f:
return json.load(f)
return []

def save_todos(todos):
with open(FILENAME, "w") as f:
json.dump(todos, f, indent=4)

todos = load_todos()

while True:
print("
1. View todos")
print("2. Add todo")
print("3. Delete todo")
print("4. Exit")

choice = input("Choose: ")

if choice == "1":
for i, task in enumerate(todos):
print(f"{i + 1}. {task}")

elif choice == "2":
task = input("New task: ").strip()
todos.append(task)
save_todos(todos)
print("Saved!")

elif choice == "3":
num = int(input("Task number to delete: ")) - 1
removed = todos.pop(num)
save_todos(todos)
print(f"Deleted: {removed}")

elif choice == "4":
break


Run it, add tasks, close it, run it again — your tasks are still there
That is persistence
Screenshot your output

⚠️ Next lecture drops in 2 days — OOP
🔥 After that we start Telegram Bots
Please open Telegram to view this post
VIEW IN TELEGRAM
This media is not supported in your browser
VIEW IN TELEGRAM
while (alive) {
repeat();
}

void repeat() {
eat();
sleep();
code();
}
📚 𝗟𝗲𝗰𝘁𝘂𝗿𝗲 𝟭𝟮 — 𝗢𝗯𝗷𝗲𝗰𝘁 𝗢𝗿𝗶𝗲𝗻𝘁𝗲𝗱 𝗣𝗿𝗼𝗴𝗿𝗮𝗺𝗺𝗶𝗻𝗴

Everything you have learned so far is procedural programming
Code that runs step by step, top to bottom

OOP is a different way of thinking about code
Instead of writing functions that do things
You create objects that have their own data and their own functions

Every major library you will use — aiogram, pyrogram, telethon — is built with OOP
You need to understand it to read and write real code

This lecture covers:
➡️ Classes and objects
➡️ Attributes and methods
➡️ The init method
➡️ Inheritance
➡️ How OOP appears in real bot code
Please open Telegram to view this post
VIEW IN TELEGRAM
📌 Classes and Objects

A class is a blueprint
An object is something built from that blueprint

Think of a class as the design for a car
An object is the actual car built from that design
You can build many cars from one design — each a separate object

class Dog:
pass # empty class for now

dog1 = Dog() # create an object from the class
dog2 = Dog() # another object — completely separate

print(type(dog1)) # <class 'main.Dog'>


dog1 and dog2 are both Dogs but they are separate objects
Changes to one do not affect the other
Please open Telegram to view this post
VIEW IN TELEGRAM
📌 init and Attributes

init runs automatically when you create an object
It is where you set the initial data for the object
self refers to the object itself

class User:
def init(self, name, age):
self.name = name
self.age = age

user1 = User("Ahmed", 22)
user2 = User("Sara", 19)

print(user1.name) # Ahmed
print(user2.age) # 19


self.name and self.age are attributes — data that belongs to each object
user1 has its own name and age, user2 has its own
They do not share data
Please open Telegram to view this post
VIEW IN TELEGRAM
📌Methods

Methods are functions that belong to a class
They always take self as the first parameter

class User:
def init(self, name, age):
self.name = name
self.age = age
self.is_banned = False

def greet(self):
print(f"Hello I am {self.name} and I am {self.age} years old")

def ban(self):
self.is_banned = True
print(f"{self.name} has been banned")

def status(self):
if self.is_banned:
print(f"{self.name}: Banned")
else:
print(f"{self.name}: Active")

user1 = User("Ahmed", 22)
user1.greet()
user1.ban()
user1.status()


Output:
Hello I am Ahmed and I am 22 years old
Ahmed has been banned
Ahmed: Banned
Please open Telegram to view this post
VIEW IN TELEGRAM
📌 Inheritance

A class can inherit from another class
It gets all the parent's attributes and methods for free
Then you add or override what you need

class User:
def init(self, name):
self.name = name

def greet(self):
print(f"Hello I am {self.name}")


class Admin(User): # Admin inherits from User
def init(self, name):
super().init(name) # call parent init
self.permissions = ["ban", "mute", "delete"]

def show_permissions(self):
print(f"{self.name} can: {', '.join(self.permissions)}")


admin = Admin("Ahmed")
admin.greet() # inherited from User
admin.show_permissions() # Admin's own method


super() calls the parent class
You will see this everywhere in aiogram and pyrogram code
Please open Telegram to view this post
VIEW IN TELEGRAM
📌 How OOP Looks in Real Bot Code

When you write a Telegram bot you will see things like this:

from aiogram import Bot, Dispatcher
from aiogram.types import Message

bot = Bot(token="YOUR_TOKEN") # creating an object from the Bot class
dp = Dispatcher() # creating an object from the Dispatcher class

@dp.message()
async def handle(message: Message): # Message is a class
print(message.text) # attribute
print(message.from_user.first_name) # nested object attribute
await message.reply("Hello!") # calling a method on the object


Bot, Dispatcher, Message — all classes
bot, dp, message — all objects
message.text, message.from_user — attributes
message.reply() — a method

Now when you see this in the next lecture it will make complete sense
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 10:35:54 → 13:51:43
Covers OOP, classes, attributes, methods, inheritance, operator overloading, and class methods
Please open Telegram to view this post
VIEW IN TELEGRAM
✏️ Lecture 12 Homework

Build a simple user management system using OOP:

class User:
def init(self, name, age):
self.name = name
self.age = age
self.is_banned = False
self.messages = []

def send_message(self, text):
if self.is_banned:
print(f"{self.name} is banned and cannot send messages")
return
self.messages.append(text)
print(f"{self.name}: {text}")

def ban(self):
self.is_banned = True
print(f"{self.name} has been banned")

def unban(self):
self.is_banned = False
print(f"{self.name} has been unbanned")

def show_history(self):
print(f"
{self.name} message history:")
for msg in self.messages:
print(f" - {msg}")


user1 = User("Ahmed", 22)
user2 = User("Sara", 19)

user1.send_message("Hello everyone!")
user2.send_message("Hey!")
user1.ban()
user1.send_message("Can you hear me?")
user1.unban()
user1.send_message("I am back!")
user1.show_history()


Run it and screenshot the output
Bonus — create an Admin class that inherits from User and has a ban() method that can ban other users

⚠️ Next lecture drops in 1 week
🔥 Python basics are done — we are going into Telegram Bots
Please open Telegram to view this post
VIEW IN TELEGRAM
This media is not supported in your browser
VIEW IN TELEGRAM
🔥 1 Week Break — Build Something

You have been learning for 12 lectures straight
Variables, strings, loops, functions, files, OOP — all of it
Now it is time to actually use it

No new lecture for 1 week
Instead — build something
Anything
From scratch, using only what you have learned so far

Ideas if you are stuck:
➡️ A to-do list that saves to a file
➡️ A quiz game with scores
➡️ A contact book with search
➡️ A simple calculator with a menu
➡️ A password generator
➡️ A number guessing game with a leaderboard
➡️ A student grade tracker

But honestly — build whatever YOU want to build
The idea does not matter, the act of building does

Rules:
➡️ No copying code from the internet
➡️ Only use what was covered in Lectures 1 to 12
➡️ It does not have to be perfect — it just has to be yours

When you are done:
➡️ Screenshot your project running
➡️ Record a short screen recording of it in action
➡️ Drop it in the comments below

I will look at every single one

New lecture drops in 7 days
See what you can build 🚀
Please open Telegram to view this post
VIEW IN TELEGRAM
⚠️ Real Talk

If nobody submits anything from the break post — I am stopping this channel

I put in the effort, you put in the work
That is the deal

Build something, screenshot it, drop it in the comments
Simple as that
Please open Telegram to view this post
VIEW IN TELEGRAM
📚 𝗟𝗲𝗰𝘁𝘂𝗿𝗲 𝟭𝟯 — 𝗛𝗼𝘄 𝗧𝗲𝗹𝗲𝗴𝗿𝗮𝗺 𝗕𝗼𝘁𝘀 𝗪𝗼𝗿𝗸

Python basics are done
Now we get to the actual reason you are here
Telegram Bots

But before writing a single line of bot code
You need to understand what is actually happening under the hood
Skipping this is why most beginners get confused later

This lecture covers:
➡️ What a Telegram bot actually is
➡️ The Bot API vs MTProto — two completely different things
➡️ What Updates are
➡️ Polling vs Webhooks
➡️ Creating your first bot with BotFather
➡️ Calling the raw API from your browser
Please open Telegram to view this post
VIEW IN TELEGRAM
📌 What is a Telegram Bot?

A Telegram bot is a special account that is controlled by code instead of a human
When someone sends your bot a message — your code receives it and decides what to do

Bots can:
➡️ Send and receive messages
➡️ Show buttons and menus
➡️ Send photos, videos, files
➡️ Work in groups and channels
➡️ Accept payments
➡️ Run games and quizzes

Bots cannot:
➡️ See messages in groups unless added or mentioned (by default)
➡️ Add themselves to groups
➡️ Message users first (users must start the bot)
Please open Telegram to view this post
VIEW IN TELEGRAM
📌 Bot API vs MTProto — The Most Important Distinction

Telegram has two completely different APIs
Most beginners do not know this and get confused

Bot API:
➡️ Official simplified API for bots
➡️ Easy to use, well documented
➡️ Has limitations — cannot read all messages, limited features
➡️ Libraries: aiogram, python-telegram-bot

MTProto:
➡️ The raw protocol the official Telegram app uses
➡️ Full power — can do virtually anything
➡️ Can act as a real user account (userbot)
➡️ Libraries: Pyrogram, Telethon

We start with Bot API using aiogram
Then move to MTProto with Pyrogram and Telethon
Both are covered in this course
Please open Telegram to view this post
VIEW IN TELEGRAM
📌 What are Updates?

Every single thing that happens on Telegram is called an Update
A message sent — Update
A button clicked — Update
Someone joining a group — Update
A photo sent — Update

Your bot's entire job is to receive Updates and respond to them

An Update looks like this in raw JSON:
{
"update_id": 123456789,
"message": {
"message_id": 1,
"from": {
"id": 987654321,
"first_name": "Ahmed",
"username": "ahmed123"
},
"chat": {
"id": 987654321,
"type": "private"
},
"text": "/start"
}
}


This is what Telegram sends your bot when someone types /start
Your code reads this and decides what to do
Libraries like aiogram handle all this for you automatically
Please open Telegram to view this post
VIEW IN TELEGRAM