Day 27 – Generators in Python
🔹 Definition:
A generator is a special type of function that returns values one at a time using
⸻
🔹 Example:
⸻
🔹 How it Works:
👉
👉 Next value is generated only when needed
👉 Saves memory compared to lists
⸻
🔹 Generator vs List
👉 Generator → produces values one by one
⸻
🔹 Generator Expression
⸻
🔹 Real-Time Example
⸻
❌ Common Mistake:
⸻
✅ Summary:
✔ Uses
✔ Generates values one by one
✔ Memory efficient
✔ Useful for large data
⸻
📢 Follow 👉 https://t.me/futurestack45
🔁 Share with friends to grow together 🚀
🔹 Definition:
A generator is a special type of function that returns values one at a time using
yield instead of returning all values at once.⸻
🔹 Example:
def my_gen():
yield 1
yield 2
yield 3
g = my_gen()
for i in g:
print(i)
Output:1
2
3
⸻
🔹 How it Works:
👉
yield pauses the function and remembers its state👉 Next value is generated only when needed
👉 Saves memory compared to lists
⸻
🔹 Generator vs List
# List
nums = [1, 2, 3]
# Generator
nums = (x for x in range(3))
👉 List → stores all values in memory👉 Generator → produces values one by one
⸻
🔹 Generator Expression
gen = (x*x for x in range(5))
for i in gen:
print(i)
Output:0
1
4
9
16
⸻
🔹 Real-Time Example
def even_numbers(n):
for i in range(n):
if i % 2 == 0:
yield i
for num in even_numbers(10):
print(num)
Output:0
2
4
6
8
⸻
❌ Common Mistake:
def test():
yield 1
print(test())
Output:<generator object test at 0x...>
❌ Because generator must be iterated to get values⸻
✅ Summary:
✔ Uses
yield instead of return✔ Generates values one by one
✔ Memory efficient
✔ Useful for large data
⸻
📢 Follow 👉 https://t.me/futurestack45
🔁 Share with friends to grow together 🚀
Telegram
FutureStack ☁️⚡
AI | Cloud | Coding | Tech Trends
Learn - Build - Grow ❤️
Job Updates: https://t.me/thinkcareers
Learn - Build - Grow ❤️
Job Updates: https://t.me/thinkcareers
❤1
Day 28 – Decorators in Python
🔹 Definition: A decorator is a function that modifies the behavior of another function without changing its code.
⸻
🔹 Basic Example:
Output:
⸻
🔹 How it Works: 👉
⸻
🔹 Without Using @ Syntax
⸻
🔹 Decorator with Arguments
Output:
⸻
🔹 Real Use Case: 👉 Logging 👉 Authentication 👉 Performance tracking
⸻
❌ Common Mistake:
❌ Missing return value handling if function returns something
⸻
✅ Summary: ✔ Used to extend function behavior ✔ Uses
⸻
📢 Follow 👉 https://t.me/futurestack45 🔁 Share with friends to grow together 🚀
🔹 Definition: A decorator is a function that modifies the behavior of another function without changing its code.
⸻
🔹 Basic Example:
def my_decorator(func):
def wrapper():
print("Before function")
func()
print("After function")
return wrapper
@my_decorator
def say_hello():
print("Hello!")
say_hello()
Output:
Before functionHello!After function⸻
🔹 How it Works: 👉
@decorator_name is used above a function 👉 It wraps another function 👉 Adds extra functionality⸻
🔹 Without Using @ Syntax
def greet():
print("Hello")
greet = my_decorator(greet)
greet()
⸻
🔹 Decorator with Arguments
def my_decorator(func):
def wrapper(name):
print("Welcome")
func(name)
return wrapper
@my_decorator
def greet(name):
print(name)
greet("Mani")
Output:
WelcomeMani⸻
🔹 Real Use Case: 👉 Logging 👉 Authentication 👉 Performance tracking
⸻
❌ Common Mistake:
def deco(func):
def wrapper():
func()
return wrapper
❌ Missing return value handling if function returns something
⸻
✅ Summary: ✔ Used to extend function behavior ✔ Uses
@ syntax ✔ Keeps code clean & reusable ✔ Very useful in real-world apps 🚀⸻
📢 Follow 👉 https://t.me/futurestack45 🔁 Share with friends to grow together 🚀
Telegram
FutureStack ☁️⚡
AI | Cloud | Coding | Tech Trends
Learn - Build - Grow ❤️
Job Updates: https://t.me/thinkcareers
Learn - Build - Grow ❤️
Job Updates: https://t.me/thinkcareers
Day 29 – Generators in Python
🔹 Definition: A generator is a function that returns values one at a time using
⸻
🔹 Basic Example:
Output:
⸻
🔹 Key Difference (return vs yield): 👉
⸻
🔹 How it Works: ✔ Function execution pauses at
⸻
🔹 Generator with Loop:
Output:
⸻
🔹 Why Use Generators? 👉 Memory efficient (no full list stored) 👉 Faster for large data 👉 Useful in streaming data
⸻
🔹 Real Use Case: ✔ Reading large files ✔ Handling API data ✔ Infinite sequences
⸻
❌ Common Mistake:
❌ This prints generator object, not values
⸻
✅ Summary: ✔ Uses
⸻
📢 Follow 👉 https://t.me/futurestack45 🔁 Share with friends to grow together 🚀
🔹 Definition: A generator is a function that returns values one at a time using
yield, instead of returning all values at once.⸻
🔹 Basic Example:
def my_generator():
yield 1
yield 2
yield 3
gen = my_generator()
for i in gen:
print(i)
Output:
123⸻
🔹 Key Difference (return vs yield): 👉
return → ends function & returns single value 👉 yield → pauses function & resumes later⸻
🔹 How it Works: ✔ Function execution pauses at
yield ✔ Remembers last state ✔ Continues from same point⸻
🔹 Generator with Loop:
def count(n):
for i in range(n):
yield i
for num in count(5):
print(num)
Output:
01234⸻
🔹 Why Use Generators? 👉 Memory efficient (no full list stored) 👉 Faster for large data 👉 Useful in streaming data
⸻
🔹 Real Use Case: ✔ Reading large files ✔ Handling API data ✔ Infinite sequences
⸻
❌ Common Mistake:
gen = my_generator()print(gen)❌ This prints generator object, not values
⸻
✅ Summary: ✔ Uses
yield keyword ✔ Generates values one by one ✔ Saves memory ✔ Ideal for large datasets 🚀⸻
📢 Follow 👉 https://t.me/futurestack45 🔁 Share with friends to grow together 🚀
Telegram
FutureStack ☁️⚡
AI | Cloud | Coding | Tech Trends
Learn - Build - Grow ❤️
Job Updates: https://t.me/thinkcareers
Learn - Build - Grow ❤️
Job Updates: https://t.me/thinkcareers
Day 30 – Lambda Functions in Python
🔹 Definition: A lambda function is a small anonymous function written in a single line without using
⸻
🔹 Basic Syntax:
⸻
🔹 Basic Example:
Output:
⸻
🔹 Key Points: ✔ No function name ✔ Single expression only ✔ Returns value automatically
⸻
🔹 With map():
Output:
⸻
🔹 With filter():
Output:
⸻
🔹 With sorted():
Output:
⸻
🔹 When to Use: 👉 Short, simple functions 👉 One-time usage 👉 Functional programming (map, filter, sort)
⸻
❌ Common Mistake: Using lambda for complex logic ❌ 👉 Makes code hard to read
⸻
✅ Summary: ✔ One-line anonymous function ✔ Uses
⸻
📢 Follow 👉 https://t.me/futurestack45 🔁 Share with friends to grow together 🚀
🔹 Definition: A lambda function is a small anonymous function written in a single line without using
def.⸻
🔹 Basic Syntax:
lambda arguments: expression⸻
🔹 Basic Example:
add = lambda a, b: a + bprint(add(2, 3))Output:
5⸻
🔹 Key Points: ✔ No function name ✔ Single expression only ✔ Returns value automatically
⸻
🔹 With map():
nums = [1, 2, 3, 4]squares = list(map(lambda x: x*x, nums))print(squares)Output:
[1, 4, 9, 16]⸻
🔹 With filter():
nums = [1, 2, 3, 4, 5]even = list(filter(lambda x: x % 2 == 0, nums))print(even)Output:
[2, 4]⸻
🔹 With sorted():
data = [(1, 'b'), (3, 'a'), (2, 'c')]result = sorted(data, key=lambda x: x[1])print(result)Output:
[(3, 'a'), (1, 'b'), (2, 'c')]⸻
🔹 When to Use: 👉 Short, simple functions 👉 One-time usage 👉 Functional programming (map, filter, sort)
⸻
❌ Common Mistake: Using lambda for complex logic ❌ 👉 Makes code hard to read
⸻
✅ Summary: ✔ One-line anonymous function ✔ Uses
lambda keyword ✔ Best for small tasks ✔ Improves code conciseness 🚀⸻
📢 Follow 👉 https://t.me/futurestack45 🔁 Share with friends to grow together 🚀
Telegram
FutureStack ☁️⚡
AI | Cloud | Coding | Tech Trends
Learn - Build - Grow ❤️
Job Updates: https://t.me/thinkcareers
Learn - Build - Grow ❤️
Job Updates: https://t.me/thinkcareers
Forwarded from Think Careers❤️
Google Free Certificate Courses — No Fees, No Experience Needed
Google offers genuinely free certificate courses across three platforms: Digital Garage, Skillshop, and Cloud Skills Boost.
Who can apply:
• Anyone with a Gmail account, no fixed eligibility criteria
• No prior experience or technical background required
• Open globally, including India
What you get:
• Google Digital Garage: Free courses on digital marketing, career development, and data skills, with certificates on completion
• Google Skillshop: 26+ official certifications in Google Ads, Analytics, and Search Ads 360, most requiring recertification every 12 months
• Google Cloud Skills Boost: 1,300+ free courses, learning pathways, and hands on labs, with completion and skill badges
• Note: Google Career Certificates on Coursera (Data Analytics, IT Support, UX Design, etc.) are not fully free, they require a paid Coursera subscription unless you qualify for financial aid or a scholarship
Documents needed: None, just a Google account
How to apply:
1. Choose your platform based on your interest: Digital Garage for marketing/career skills, Skillshop for Ads/Analytics certifications, or Cloud Skills Boost for cloud/data skills
2. Sign in with your Gmail account
3. Enroll in your chosen course
4. Complete the video lessons, quizzes, and assignments
5. Download your certificate or badge upon completion
Deadline: None, self-paced and available anytime
Apply here:
Digital Garage: https://grow.google/digitalgarage
Skillshop: https://skillshop.withgoogle.com
Cloud Skills Boost: https://cloudskillsboost.google
Google offers genuinely free certificate courses across three platforms: Digital Garage, Skillshop, and Cloud Skills Boost.
Who can apply:
• Anyone with a Gmail account, no fixed eligibility criteria
• No prior experience or technical background required
• Open globally, including India
What you get:
• Google Digital Garage: Free courses on digital marketing, career development, and data skills, with certificates on completion
• Google Skillshop: 26+ official certifications in Google Ads, Analytics, and Search Ads 360, most requiring recertification every 12 months
• Google Cloud Skills Boost: 1,300+ free courses, learning pathways, and hands on labs, with completion and skill badges
• Note: Google Career Certificates on Coursera (Data Analytics, IT Support, UX Design, etc.) are not fully free, they require a paid Coursera subscription unless you qualify for financial aid or a scholarship
Documents needed: None, just a Google account
How to apply:
1. Choose your platform based on your interest: Digital Garage for marketing/career skills, Skillshop for Ads/Analytics certifications, or Cloud Skills Boost for cloud/data skills
2. Sign in with your Gmail account
3. Enroll in your chosen course
4. Complete the video lessons, quizzes, and assignments
5. Download your certificate or badge upon completion
Deadline: None, self-paced and available anytime
Apply here:
Digital Garage: https://grow.google/digitalgarage
Skillshop: https://skillshop.withgoogle.com
Cloud Skills Boost: https://cloudskillsboost.google
Grow with Google US
Grow with Google - Training to Grow Your Business & Career.
Explore training and tools to grow your business and online presence and learn digital skills to grow your career and qualify for in-demand jobs
Day 31 – Modules & Packages in Python
🔹 Definition: A module is a file containing Python code (functions, variables). A package is a collection of multiple modules organized in folders.
⸻
🔹 Example (Module):
👉 Create a file
👉 Use in another file:
Output:
⸻
🔹 Import Methods:
⸻
🔹 Creating Package Structure:
👉Definition
⸻
🔹 Using Package:
⸻
🔹 Why Use Modules & Packages? ✔ Organize large code ✔ Improve readability ✔ Reuse code easily ✔ Avoid duplication
⸻
🔹 Built-in Modules Examples: 👉 math 👉 random 👉 datetime
⸻
❌ Common Mistake:
❌ Imports everything → can cause conflicts
⸻
✅ Summary: ✔ Module = single Python file ✔ Package = collection of modules ✔ Use
⸻
📢 Follow 👉 https://t.me/futurestack45 🔁 Share with friends to grow together 🚀
🔹 Definition: A module is a file containing Python code (functions, variables). A package is a collection of multiple modules organized in folders.
⸻
🔹 Example (Module):
👉 Create a file
math_utils.pydef add(a, b): return a + b👉 Use in another file:
import math_utilsprint(math_utils.add(2, 3))Output:
5⸻
🔹 Import Methods:
import mathprint(math.sqrt(16))from math import sqrtprint(sqrt(25))from math import *print(pow(2, 3))⸻
🔹 Creating Package Structure:
my_package/ ├── __init__.py ├── module1.py └── module2.py👉Definition
py makes folder a package⸻
🔹 Using Package:
from my_package import module1⸻
🔹 Why Use Modules & Packages? ✔ Organize large code ✔ Improve readability ✔ Reuse code easily ✔ Avoid duplication
⸻
🔹 Built-in Modules Examples: 👉 math 👉 random 👉 datetime
⸻
❌ Common Mistake:
from math import *❌ Imports everything → can cause conflicts
⸻
✅ Summary: ✔ Module = single Python file ✔ Package = collection of modules ✔ Use
import to access ✔ Keeps code clean & scalable 🚀⸻
📢 Follow 👉 https://t.me/futurestack45 🔁 Share with friends to grow together 🚀
Telegram
FutureStack ☁️⚡
AI | Cloud | Coding | Tech Trends
Learn - Build - Grow ❤️
Job Updates: https://t.me/thinkcareers
Learn - Build - Grow ❤️
Job Updates: https://t.me/thinkcareers
❤2
Day 32 – Virtual Environment in Python
🔹 Definition: A virtual environment is an isolated space where you can install Python packages separately for each project.
⸻
🔹 Why Use Virtual Environment? 👉 Avoid package conflicts 👉 Manage project dependencies 👉 Keep projects clean and independent
⸻
🔹 Create Virtual Environment:
⸻
🔹 Activate Virtual Environment:
👉 Windows:
👉 Mac/Linux:
⸻
🔹 Install Packages:
⸻
🔹 Deactivate Environment:
⸻
🔹 Check Installed Packages:
⸻
🔹 Freeze Requirements:
👉 Helps to share project dependencies
⸻
🔹 Install from Requirements File:
⸻
❌ Common Mistake: 👉 Installing packages globally instead of using virtual environment ❌
⸻
✅ Summary: ✔ Isolated Python environment ✔ Avoids dependency conflicts ✔ Essential for real-world projects ✔ Use
⸻
📢 Follow 👉 https://t.me/futurestack45 🔁 Share with friends to grow together 🚀
🔹 Definition: A virtual environment is an isolated space where you can install Python packages separately for each project.
⸻
🔹 Why Use Virtual Environment? 👉 Avoid package conflicts 👉 Manage project dependencies 👉 Keep projects clean and independent
⸻
🔹 Create Virtual Environment:
python -m venv myenv⸻
🔹 Activate Virtual Environment:
👉 Windows:
myenv\Scripts\activate👉 Mac/Linux:
source myenv/bin/activate⸻
🔹 Install Packages:
pip install requests⸻
🔹 Deactivate Environment:
deactivate⸻
🔹 Check Installed Packages:
pip list⸻
🔹 Freeze Requirements:
pip freeze > requirements.txt👉 Helps to share project dependencies
⸻
🔹 Install from Requirements File:
pip install -r requirements.txt⸻
❌ Common Mistake: 👉 Installing packages globally instead of using virtual environment ❌
⸻
✅ Summary: ✔ Isolated Python environment ✔ Avoids dependency conflicts ✔ Essential for real-world projects ✔ Use
venv module 🚀⸻
📢 Follow 👉 https://t.me/futurestack45 🔁 Share with friends to grow together 🚀
Telegram
FutureStack ☁️⚡
AI | Cloud | Coding | Tech Trends
Learn - Build - Grow ❤️
Job Updates: https://t.me/thinkcareers
Learn - Build - Grow ❤️
Job Updates: https://t.me/thinkcareers
Day 33 – File Handling in Python
🔹 Definition: File handling allows you to create, read, write, and manage files using Python.
⸻
🔹 Open a File:
👉 Modes:
⸻
🔹 Read File:
⸻
🔹 Read Line by Line:
⸻
🔹 Write to File:
⸻
🔹 Append Data:
⸻
🔹 Best Practice (with statement):
👉 Automatically closes file ✅
⸻
🔹 Check if File Exists:
⸻
❌ Common Mistakes: 👉 Forgetting to close file ❌ 👉 Using wrong mode (w deletes data) ❌
⸻
✅ Summary: ✔ Open, read, write files easily ✔ Use correct mode ✔ Prefer
⸻
📢 Follow 👉 https://t.me/futurestack45 🔁 Share with friends to grow together 🚀
🔹 Definition: File handling allows you to create, read, write, and manage files using Python.
⸻
🔹 Open a File:
file = open("data.txt", "r")👉 Modes:
"r" → Read"w" → Write (overwrites)"a" → Append"x" → Create⸻
🔹 Read File:
file = open("data.txt", "r")print(file.read())file.close()⸻
🔹 Read Line by Line:
file = open("data.txt", "r")for line in file: print(line)file.close()⸻
🔹 Write to File:
file = open("data.txt", "w")file.write("Hello World")file.close()⸻
🔹 Append Data:
file = open("data.txt", "a")file.write("\nNew Line")file.close()⸻
🔹 Best Practice (with statement):
with open("data.txt", "r") as file: print(file.read())👉 Automatically closes file ✅
⸻
🔹 Check if File Exists:
import osprint(os.path.exists("data.txt"))⸻
❌ Common Mistakes: 👉 Forgetting to close file ❌ 👉 Using wrong mode (w deletes data) ❌
⸻
✅ Summary: ✔ Open, read, write files easily ✔ Use correct mode ✔ Prefer
with for safety ✔ Important for real-world apps 🚀⸻
📢 Follow 👉 https://t.me/futurestack45 🔁 Share with friends to grow together 🚀
Telegram
FutureStack ☁️⚡
AI | Cloud | Coding | Tech Trends
Learn - Build - Grow ❤️
Job Updates: https://t.me/thinkcareers
Learn - Build - Grow ❤️
Job Updates: https://t.me/thinkcareers
Day 34 – Working with JSON in Python
🔹 Definition: JSON (JavaScript Object Notation) is a format used to store and exchange data. Python provides a built-in
⸻
🔹 Convert Python → JSON:
👉 Converts dictionary into JSON string
⸻
🔹 Convert JSON → Python:
👉 Converts JSON string into dictionary
⸻
🔹 Write JSON to File:
⸻
🔹 Read JSON from File:
⸻
🔹 Pretty Print JSON:
⸻
🔹 Common Use Cases: ✔ APIs (sending & receiving data) ✔ Configuration files ✔ Data storage
⸻
❌ Common Mistakes: 👉 Using single quotes in JSON ❌ 👉 Confusing
⸻
✅ Summary: ✔ JSON = data exchange format ✔
⸻
📢 Follow 👉 https://t.me/futurestack45 🔁 Share with friends to grow together 🚀
🔹 Definition: JSON (JavaScript Object Notation) is a format used to store and exchange data. Python provides a built-in
json module to work with it.⸻
🔹 Convert Python → JSON:
import jsondata = {"name": "John", "age": 25}json_data = json.dumps(data)print(json_data)👉 Converts dictionary into JSON string
⸻
🔹 Convert JSON → Python:
import jsonjson_data = '{"name": "John", "age": 25}'data = json.loads(json_data)print(data["name"])👉 Converts JSON string into dictionary
⸻
🔹 Write JSON to File:
import jsondata = {"name": "Alice", "age": 22}with open("data.json", "w") as file: json.dump(data, file)⸻
🔹 Read JSON from File:
import jsonwith open("data.json", "r") as file: data = json.load(file)print(data)⸻
🔹 Pretty Print JSON:
import jsondata = {"name": "Sam", "age": 30}print(json.dumps(data, indent=4))⸻
🔹 Common Use Cases: ✔ APIs (sending & receiving data) ✔ Configuration files ✔ Data storage
⸻
❌ Common Mistakes: 👉 Using single quotes in JSON ❌ 👉 Confusing
dump vs dumps ❌⸻
✅ Summary: ✔ JSON = data exchange format ✔
dumps / loads → string ✔ dump / load → file ✔ Widely used in real-world apps 🚀⸻
📢 Follow 👉 https://t.me/futurestack45 🔁 Share with friends to grow together 🚀
Telegram
FutureStack ☁️⚡
AI | Cloud | Coding | Tech Trends
Learn - Build - Grow ❤️
Job Updates: https://t.me/thinkcareers
Learn - Build - Grow ❤️
Job Updates: https://t.me/thinkcareers
Day 35 – Working with APIs in Python
🔹 Definition: API (Application Programming Interface) allows applications to communicate with each other and exchange data.
⸻
🔹 Why Use APIs? 👉 Get real-time data (weather, users, payments) 👉 Connect frontend ↔ backend 👉 Integrate third-party services
⸻
🔹 Install Requests Library:
⸻
🔹 Make GET Request:
⸻
🔹 Get JSON Data:
⸻
🔹 POST Request Example:
⸻
🔹 Status Codes: 👉 200 → Success ✅ 👉 404 → Not Found ❌ 👉 500 → Server Error ❌
⸻
🔹 Headers Example:
⸻
❌ Common Mistakes: 👉 Not checking status code ❌ 👉 Forgetting
⸻
✅ Summary: ✔ APIs connect applications ✔ Use
⸻
📢 Follow 👉 https://t.me/futurestack45 🔁 Share with friends to grow together 🚀
🔹 Definition: API (Application Programming Interface) allows applications to communicate with each other and exchange data.
⸻
🔹 Why Use APIs? 👉 Get real-time data (weather, users, payments) 👉 Connect frontend ↔ backend 👉 Integrate third-party services
⸻
🔹 Install Requests Library:
pip install requests⸻
🔹 Make GET Request:
import requestsresponse = requests.get("https://api.github.com")print(response.status_code)print(response.text)⸻
🔹 Get JSON Data:
import requestsresponse = requests.get("https://api.github.com")data = response.json()print(data)⸻
🔹 POST Request Example:
import requestsdata = {"name": "John"}response = requests.post("https://httpbin.org/post", json=data)print(response.json())⸻
🔹 Status Codes: 👉 200 → Success ✅ 👉 404 → Not Found ❌ 👉 500 → Server Error ❌
⸻
🔹 Headers Example:
headers = {"Authorization": "Bearer token"}requests.get("https://api.example.com", headers=headers)⸻
❌ Common Mistakes: 👉 Not checking status code ❌ 👉 Forgetting
.json() for JSON response ❌⸻
✅ Summary: ✔ APIs connect applications ✔ Use
requests module ✔ GET → fetch data ✔ POST → send data ✔ Used in real-world apps 🚀⸻
📢 Follow 👉 https://t.me/futurestack45 🔁 Share with friends to grow together 🚀
Day 36 – Introduction to Databases (SQLite in Python)
🔹 Definition: A database is used to store, manage, and retrieve structured data efficiently. SQLite is a lightweight, built-in database in Python.
⸻
🔹 Why Use Database? 👉 Store large data 👉 Retrieve data quickly 👉 Avoid data loss 👉 Used in real-world applications
⸻
🔹 Connect to Database:
⸻
🔹 Create Table:
⸻
🔹 Insert Data:
⸻
🔹 Fetch Data:
⸻
🔹 Update Data:
⸻
🔹 Delete Data:
⸻
🔹 Close Connection:
⸻
❌ Common Mistakes: 👉 Forgetting
⸻
✅ Summary: ✔ SQLite = built-in database ✔ Store & manage structured data ✔ Use SQL queries in Python ✔ Essential for backend development 🚀
⸻
📢 Follow 👉 https://t.me/futurestack45 🔁 Share with friends to grow together 🚀
🔹 Definition: A database is used to store, manage, and retrieve structured data efficiently. SQLite is a lightweight, built-in database in Python.
⸻
🔹 Why Use Database? 👉 Store large data 👉 Retrieve data quickly 👉 Avoid data loss 👉 Used in real-world applications
⸻
🔹 Connect to Database:
import sqlite3conn = sqlite3.connect("mydb.db")cursor = conn.cursor()⸻
🔹 Create Table:
cursor.execute("""CREATE TABLE users ( id INTEGER PRIMARY KEY, name TEXT, age INTEGER)""")⸻
🔹 Insert Data:
cursor.execute("INSERT INTO users (name, age) VALUES (?, ?)", ("John", 25))conn.commit()⸻
🔹 Fetch Data:
cursor.execute("SELECT * FROM users")rows = cursor.fetchall()for row in rows: print(row)⸻
🔹 Update Data:
cursor.execute("UPDATE users SET age = ? WHERE name = ?", (30, "John"))conn.commit()⸻
🔹 Delete Data:
cursor.execute("DELETE FROM users WHERE name = ?", ("John",))conn.commit()⸻
🔹 Close Connection:
conn.close()⸻
❌ Common Mistakes: 👉 Forgetting
commit() ❌ 👉 Not closing connection ❌⸻
✅ Summary: ✔ SQLite = built-in database ✔ Store & manage structured data ✔ Use SQL queries in Python ✔ Essential for backend development 🚀
⸻
📢 Follow 👉 https://t.me/futurestack45 🔁 Share with friends to grow together 🚀
Telegram
FutureStack ☁️⚡
AI | Cloud | Coding | Tech Trends
Learn - Build - Grow ❤️
Job Updates: https://t.me/thinkcareers
Learn - Build - Grow ❤️
Job Updates: https://t.me/thinkcareers
Day 37 – Command Line Arguments in Python
🔹 Definition: Command line arguments allow you to pass input values to a Python script when running it from the terminal.
⸻
🔹 Why Use It? 👉 Pass dynamic input without changing code 👉 Useful for scripts & automation 👉 Common in real-world tools
⸻
🔹 Using sys Module:
👉
⸻
🔹 Example:
⸻
🔹 Convert Input Type:
⸻
🔹 Using argparse (Better Way):
⸻
🔹 Run Script:
Output:
⸻
❌ Common Mistakes: 👉 Forgetting index starts from 0 ❌ 👉 Not converting string to int ❌
⸻
✅ Summary: ✔ Use
⸻
📢 Follow 👉 https://t.me/futurestack45 🔁 Share with friends to grow together 🚀
🔹 Definition: Command line arguments allow you to pass input values to a Python script when running it from the terminal.
⸻
🔹 Why Use It? 👉 Pass dynamic input without changing code 👉 Useful for scripts & automation 👉 Common in real-world tools
⸻
🔹 Using sys Module:
import sysprint(sys.argv)👉
sys.argv stores all command line inputs as a list⸻
🔹 Example:
python script.py hello 123import sysprint(sys.argv[0]) # script nameprint(sys.argv[1]) # helloprint(sys.argv[2]) # 123⸻
🔹 Convert Input Type:
import sysnum = int(sys.argv[1])print(num * 2)⸻
🔹 Using argparse (Better Way):
import argparseparser = argparse.ArgumentParser()parser.add_argument("name")args = parser.parse_args()print("Hello", args.name)⸻
🔹 Run Script:
python script.py JohnOutput:
Hello John⸻
❌ Common Mistakes: 👉 Forgetting index starts from 0 ❌ 👉 Not converting string to int ❌
⸻
✅ Summary: ✔ Use
sys.argv for basic input ✔ Use argparse for advanced usage ✔ Helpful for automation scripts ✔ Widely used in real-world tools 🚀⸻
📢 Follow 👉 https://t.me/futurestack45 🔁 Share with friends to grow together 🚀
Telegram
FutureStack ☁️⚡
AI | Cloud | Coding | Tech Trends
Learn - Build - Grow ❤️
Job Updates: https://t.me/thinkcareers
Learn - Build - Grow ❤️
Job Updates: https://t.me/thinkcareers
Day 38 – Scope & LEGB Rule in Python
🔹 Definition: Scope determines where a variable can be accessed in a Python program.
Python mainly follows four levels of scope:
👉 L – Local 👉 E – Enclosing 👉 G – Global 👉 B – Built-in
Together, these are called the LEGB rule.
⸻
🔹 1️⃣ Local Scope
👉 A variable created inside a function is called a local variable. 👉 It can normally be accessed only inside that function.
Example:
Output:
❌ This will cause an error:
👉
⸻
🔹 2️⃣ Global Scope
👉 A variable created outside a function is called a global variable. 👉 It can be accessed from different parts of the program.
Example:
Output:
⸻
🔹 3️⃣ Enclosing Scope
👉 This occurs when one function is defined inside another function. 👉 A variable from the outer function can be accessed by the inner function.
Example:
Output:
⸻
🔹 4️⃣ Built-in Scope
👉 Python provides many built-in names that can be used directly.
Examples:
Output:
👉
⸻
🔹 LEGB Rule
When Python looks for a variable, it searches in this order:
👉 L → Local 👉 E → Enclosing 👉 G → Global 👉 B → Built-in
Example:
Output:
👉 Python finds the nearest
⸻
🔹 global Keyword
👉 The
Example:
Output:
⸻
🔹 nonlocal Keyword
👉 The
Example:
Output:
⸻
❌ Common Mistakes:
🚫 Confusing local and global variables 🚫 Trying to access a local variable outside its function 🚫 Using
⸻
✅ Summary:
✔ Scope → where a variable can be accessed ✔ Local → inside current function ✔ Enclosing → outer function ✔ Global → outside functions ✔ Built-in → Python’s predefined names ✔ LEGB → order Python uses to find variables 🚀
⸻
📢 Follow 👉 https://t.me/futurestack45 🔁 Share with friends to grow together 🚀
🔹 Definition: Scope determines where a variable can be accessed in a Python program.
Python mainly follows four levels of scope:
👉 L – Local 👉 E – Enclosing 👉 G – Global 👉 B – Built-in
Together, these are called the LEGB rule.
⸻
🔹 1️⃣ Local Scope
👉 A variable created inside a function is called a local variable. 👉 It can normally be accessed only inside that function.
Example:
def greet(): message = "Hello" print(message)greet()Output:
Hello❌ This will cause an error:
def greet(): message = "Hello"greet()print(message)👉
message exists only inside greet().⸻
🔹 2️⃣ Global Scope
👉 A variable created outside a function is called a global variable. 👉 It can be accessed from different parts of the program.
Example:
name = "Python"def show(): print(name)show()Output:
Python⸻
🔹 3️⃣ Enclosing Scope
👉 This occurs when one function is defined inside another function. 👉 A variable from the outer function can be accessed by the inner function.
Example:
def outer(): message = "Hello" def inner(): print(message) inner()outer()Output:
Hello⸻
🔹 4️⃣ Built-in Scope
👉 Python provides many built-in names that can be used directly.
Examples:
print(len("Python"))print(max(10, 20))Output:
620👉
print(), len(), max(), sum() etc. are built-in functions.⸻
🔹 LEGB Rule
When Python looks for a variable, it searches in this order:
👉 L → Local 👉 E → Enclosing 👉 G → Global 👉 B → Built-in
Example:
x = "Global"def outer(): x = "Enclosing" def inner(): x = "Local" print(x) inner()outer()Output:
Local👉 Python finds the nearest
x first.⸻
🔹 global Keyword
👉 The
global keyword allows a function to modify a global variable.Example:
count = 10def update(): global count count = 20update()print(count)Output:
20⸻
🔹 nonlocal Keyword
👉 The
nonlocal keyword allows an inner function to modify a variable from its enclosing function.Example:
def outer(): count = 10 def inner(): nonlocal count count = 20 inner() print(count)outer()Output:
20⸻
❌ Common Mistakes:
🚫 Confusing local and global variables 🚫 Trying to access a local variable outside its function 🚫 Using
global unnecessarily⸻
✅ Summary:
✔ Scope → where a variable can be accessed ✔ Local → inside current function ✔ Enclosing → outer function ✔ Global → outside functions ✔ Built-in → Python’s predefined names ✔ LEGB → order Python uses to find variables 🚀
⸻
📢 Follow 👉 https://t.me/futurestack45 🔁 Share with friends to grow together 🚀
Telegram
FutureStack ☁️⚡
AI | Cloud | Coding | Tech Trends
Learn - Build - Grow ❤️
Job Updates: https://t.me/thinkcareers
Learn - Build - Grow ❤️
Job Updates: https://t.me/thinkcareers
Day 39 – map(), filter() & reduce() in Python
🔹 Definition: These are functions used to process collections such as lists and perform operations on multiple values efficiently.
⸻
🔹 1️⃣ map()
👉
Example:
Output:
👉 Every number is multiplied by
⸻
🔹 2️⃣ filter()
👉
Example:
Output:
👉 Only even numbers are selected.
⸻
🔹 3️⃣ reduce()
👉
👉 It is available in the
Example:
Output:
👉 Calculation:
⸻
🔹 map() Example Without Lambda
Output:
⸻
🔹 filter() Example Without Lambda
Output:
⸻
🔹 Important Difference
👉
👉
👉
⸻
🔹 Real-World Example
Suppose we have marks:
Output:
👉
⸻
❌ Common Mistakes:
🚫 Forgetting
🚫 Using
🚫 Forgetting to import
⸻
✅ Summary:
✔
⸻
📢 Follow 👉 https://t.me/futurestack45 🔁 Share with friends to grow together 🚀
🔹 Definition: These are functions used to process collections such as lists and perform operations on multiple values efficiently.
⸻
🔹 1️⃣ map()
👉
map() applies a function to every element of an iterable and returns the results.Example:
numbers = [1, 2, 3, 4]result = list(map(lambda x: x * 2, numbers))print(result)Output:
[2, 4, 6, 8]👉 Every number is multiplied by
2.⸻
🔹 2️⃣ filter()
👉
filter() selects only the elements that satisfy a condition.Example:
numbers = [1, 2, 3, 4, 5, 6]result = list(filter(lambda x: x % 2 == 0, numbers))print(result)Output:
[2, 4, 6]👉 Only even numbers are selected.
⸻
🔹 3️⃣ reduce()
👉
reduce() repeatedly combines elements and produces one final value.👉 It is available in the
functools module.Example:
from functools import reducenumbers = [1, 2, 3, 4]result = reduce(lambda a, b: a + b, numbers)print(result)Output:
10👉 Calculation:
1 + 2 + 3 + 4 = 10⸻
🔹 map() Example Without Lambda
def square(x): return x * xnumbers = [1, 2, 3, 4]result = list(map(square, numbers))print(result)Output:
[1, 4, 9, 16]⸻
🔹 filter() Example Without Lambda
def is_positive(x): return x > 0numbers = [-2, -1, 0, 1, 2]result = list(filter(is_positive, numbers))print(result)Output:
[1, 2]⸻
🔹 Important Difference
👉
map() → Transforms every element👉
filter() → Selects elements👉
reduce() → Combines elements into one result⸻
🔹 Real-World Example
Suppose we have marks:
marks = [35, 80, 45, 90, 20]passed = list(filter(lambda x: x >= 40, marks))print(passed)Output:
[80, 45, 90]👉
filter() keeps only students who scored 40 or above.⸻
❌ Common Mistakes:
🚫 Forgetting
list() when you want to display the results directly🚫 Using
filter() when you actually need to transform values🚫 Forgetting to import
reduce⸻
✅ Summary:
✔
map() → transform values ✔ filter() → select values ✔ reduce() → combine values ✔ Often used with lambda functions ✔ Very useful for processing collections 🚀⸻
📢 Follow 👉 https://t.me/futurestack45 🔁 Share with friends to grow together 🚀
Telegram
FutureStack ☁️⚡
AI | Cloud | Coding | Tech Trends
Learn - Build - Grow ❤️
Job Updates: https://t.me/thinkcareers
Learn - Build - Grow ❤️
Job Updates: https://t.me/thinkcareers
Day 40 – Iterators in Python
🔹 Definition: An iterator is an object that allows you to access elements one at a time, without accessing all elements at once.
👉 Python uses
⸻
🔹 Basic Example:
Output:
👉 Each
⸻
🔹 How iter() Works
👉
Example:
👉 The iterator keeps track of where it is in the sequence.
⸻
🔹 How next() Works
👉
Example:
Output:
⸻
🔹 What Happens When Values Are Finished?
If there are no more values, Python raises
Example:
Output:
👉
⸻
🔹 Iterator with for Loop
You normally don’t need to call
Example:
Output:
👉 The
⸻
🔹 Iterable vs Iterator
👉 Iterable: An object whose elements can be accessed one by one.
Examples:
👉 Iterator: An object that remembers its current position while producing values.
Example:
⸻
🔹 Creating Your Own Iterator
A class can be made into an iterator using
Example:
Output:
⸻
🔹 Iterator vs Generator
👉 Iterator → object that implements
👉 Generator → simpler way to create an iterator using
Example:
Output:
⸻
❌ Common Mistakes:
🚫 Calling
⸻
✅ Summary:
✔ Iterator → accesses values one at a time ✔
⸻
📢 Follow 👉 https://t.me/futurestack45 🔁 Share with friends to grow together 🚀
🔹 Definition: An iterator is an object that allows you to access elements one at a time, without accessing all elements at once.
👉 Python uses
iter() to create an iterator and next() to get the next value.⸻
🔹 Basic Example:
numbers = [10, 20, 30]iterator = iter(numbers)print(next(iterator))print(next(iterator))print(next(iterator))Output:
102030👉 Each
next() call returns the next element.⸻
🔹 How iter() Works
👉
iter() converts an iterable such as a list into an iterator.Example:
numbers = [1, 2, 3]iterator = iter(numbers)print(iterator)👉 The iterator keeps track of where it is in the sequence.
⸻
🔹 How next() Works
👉
next() retrieves the next available value from an iterator.Example:
numbers = [10, 20, 30]iterator = iter(numbers)print(next(iterator))print(next(iterator))Output:
1020⸻
🔹 What Happens When Values Are Finished?
If there are no more values, Python raises
StopIteration.Example:
numbers = [1, 2]iterator = iter(numbers)print(next(iterator))print(next(iterator))print(next(iterator))Output:
12Traceback (most recent call last):...StopIteration👉
StopIteration tells Python that there are no more elements.⸻
🔹 Iterator with for Loop
You normally don’t need to call
next() manually.Example:
numbers = [10, 20, 30]for num in numbers: print(num)Output:
102030👉 The
for loop internally uses the iterator mechanism.⸻
🔹 Iterable vs Iterator
👉 Iterable: An object whose elements can be accessed one by one.
Examples:
numbers = [1, 2, 3]name = "Python"👉 Iterator: An object that remembers its current position while producing values.
Example:
numbers = [1, 2, 3]iterator = iter(numbers)⸻
🔹 Creating Your Own Iterator
A class can be made into an iterator using
__iter__() and __next__().Example:
class Count: def __init__(self): self.num = 1 def __iter__(self): return self def __next__(self): if self.num <= 3: value = self.num self.num += 1 return value raise StopIterationcounter = Count()for num in counter: print(num)Output:
123⸻
🔹 Iterator vs Generator
👉 Iterator → object that implements
__iter__() and __next__()👉 Generator → simpler way to create an iterator using
yieldExample:
def numbers(): yield 1 yield 2 yield 3for num in numbers(): print(num)Output:
123⸻
❌ Common Mistakes:
🚫 Calling
next() after all elements are consumed 🚫 Confusing an iterable with an iterator 🚫 Forgetting that an iterator keeps its current position⸻
✅ Summary:
✔ Iterator → accesses values one at a time ✔
iter() → creates an iterator ✔ next() → gets the next value ✔ StopIteration → indicates no more values ✔ for loop uses iteration internally ✔ Generators are an easy way to create iterators 🚀⸻
📢 Follow 👉 https://t.me/futurestack45 🔁 Share with friends to grow together 🚀
Telegram
FutureStack ☁️⚡
AI | Cloud | Coding | Tech Trends
Learn - Build - Grow ❤️
Job Updates: https://t.me/thinkcareers
Learn - Build - Grow ❤️
Job Updates: https://t.me/thinkcareers
Day 41 – zip() & enumerate() in Python
🔹 Definition:
⸻
🔹 1️⃣ zip()
👉
Example:
Output:
👉 First name is combined with the first age, second with second, and so on.
⸻
🔹 Using zip() with a for Loop
Output:
⸻
🔹 2️⃣ enumerate()
👉
Example:
Output:
👉 By default, counting starts from
⸻
🔹 Start enumerate() from 1
Output:
⸻
🔹 Why Use enumerate()?
❌ Without
✅ With
👉
⸻
🔹 Combining zip() + enumerate()
Output:
⸻
🔹 Important Point About zip()
👉 If the iterables have different lengths,
Example:
Output:
👉
⸻
❌ Common Mistakes:
🚫 Forgetting that indexes start from
⸻
✅ Summary:
✔
⸻
📢 Follow 👉 https://t.me/futurestack45 🔁 Share with friends to grow together 🚀
🔹 Definition:
zip() and enumerate() are built-in Python functions that make it easier to work with lists and other iterables.⸻
🔹 1️⃣ zip()
👉
zip() combines elements from two or more iterables position by position.Example:
names = ["Mani", "Rahul", "Priya"]ages = [22, 24, 21]result = zip(names, ages)print(list(result))Output:
[('Mani', 22), ('Rahul', 24), ('Priya', 21)]👉 First name is combined with the first age, second with second, and so on.
⸻
🔹 Using zip() with a for Loop
names = ["Mani", "Rahul", "Priya"]marks = [85, 90, 78]for name, mark in zip(names, marks): print(name, mark)Output:
Mani 85Rahul 90Priya 78⸻
🔹 2️⃣ enumerate()
👉
enumerate() adds a counter/index while looping through an iterable.Example:
names = ["Mani", "Rahul", "Priya"]for index, name in enumerate(names): print(index, name)Output:
0 Mani1 Rahul2 Priya👉 By default, counting starts from
0.⸻
🔹 Start enumerate() from 1
names = ["Mani", "Rahul", "Priya"]for index, name in enumerate(names, start=1): print(index, name)Output:
1 Mani2 Rahul3 Priya⸻
🔹 Why Use enumerate()?
❌ Without
enumerate():names = ["Mani", "Rahul", "Priya"]for i in range(len(names)): print(i, names[i])✅ With
enumerate():names = ["Mani", "Rahul", "Priya"]for i, name in enumerate(names): print(i, name)👉
enumerate() makes the code cleaner and easier to read.⸻
🔹 Combining zip() + enumerate()
names = ["Mani", "Rahul", "Priya"]marks = [85, 90, 78]for index, (name, mark) in enumerate(zip(names, marks), start=1): print(index, name, mark)Output:
1 Mani 852 Rahul 903 Priya 78⸻
🔹 Important Point About zip()
👉 If the iterables have different lengths,
zip() stops when the shortest iterable ends.Example:
names = ["Mani", "Rahul", "Priya"]ages = [22, 24]print(list(zip(names, ages)))Output:
[('Mani', 22), ('Rahul', 24)]👉
Priya has no matching age, so she is not included.⸻
❌ Common Mistakes:
🚫 Forgetting that indexes start from
0 🚫 Assuming zip() fills missing values 🚫 Forgetting to convert zip() to list() when you want to display all pairs directly⸻
✅ Summary:
✔
zip() → combines values position by position ✔ enumerate() → adds index while looping ✔ enumerate(..., start=1) → starts counting from 1 ✔ zip() stops at the shortest iterable ✔ Both make loops cleaner and easier to understand 🚀⸻
📢 Follow 👉 https://t.me/futurestack45 🔁 Share with friends to grow together 🚀
Telegram
FutureStack ☁️⚡
AI | Cloud | Coding | Tech Trends
Learn - Build - Grow ❤️
Job Updates: https://t.me/thinkcareers
Learn - Build - Grow ❤️
Job Updates: https://t.me/thinkcareers
Day 42 – any(), all(), min(), max() & sum() in Python
🔹 Definition: Python provides several built-in functions that make it easier to check conditions and perform calculations on collections of values.
⸻
🔹 1️⃣ any()
👉
Example:
Output:
👉
⸻
🔹 2️⃣ all()
👉
Example:
Output:
👉 Every number is even.
⸻
🔹 any() vs all()
👉
👉
Example:
Output:
👉 At least one number is even →
👉 Not all numbers are even →
⸻
🔹 3️⃣ min()
👉
Example:
Output:
⸻
🔹 4️⃣ max()
👉
Example:
Output:
⸻
🔹 5️⃣ sum()
👉
Example:
Output:
⸻
🔹 Real-World Example
Suppose we have student marks:
Output:
⸻
🔹 Checking if Any Student Failed
Output:
👉 At least one student scored below 40.
⸻
❌ Common Mistakes:
🚫 Confusing
🚫 Using
🚫 Forgetting that
⸻
✅ Summary:
✔
🚀 These built-in functions are extremely useful when working with lists and other collections.
⸻
📢 Follow 👉 https://t.me/futurestack45 🔁 Share with friends to grow together 🚀
🔹 Definition: Python provides several built-in functions that make it easier to check conditions and perform calculations on collections of values.
⸻
🔹 1️⃣ any()
👉
any() returns True if at least one value in an iterable is True.Example:
numbers = [1, 3, 5, 8]result = any(x % 2 == 0 for x in numbers)print(result)Output:
True👉
8 is even, so at least one condition is True.⸻
🔹 2️⃣ all()
👉
all() returns True only when every value in an iterable is True.Example:
numbers = [2, 4, 6, 8]result = all(x % 2 == 0 for x in numbers)print(result)Output:
True👉 Every number is even.
⸻
🔹 any() vs all()
👉
any() → At least one must be True👉
all() → Every condition must be TrueExample:
numbers = [2, 4, 7, 8]print(any(x % 2 == 0 for x in numbers))print(all(x % 2 == 0 for x in numbers))Output:
TrueFalse👉 At least one number is even →
True👉 Not all numbers are even →
False⸻
🔹 3️⃣ min()
👉
min() returns the smallest value from a collection.Example:
numbers = [10, 5, 20, 3]print(min(numbers))Output:
3⸻
🔹 4️⃣ max()
👉
max() returns the largest value from a collection.Example:
numbers = [10, 5, 20, 3]print(max(numbers))Output:
20⸻
🔹 5️⃣ sum()
👉
sum() calculates the total of numeric values.Example:
numbers = [10, 20, 30, 40]print(sum(numbers))Output:
100⸻
🔹 Real-World Example
Suppose we have student marks:
marks = [75, 82, 68, 91, 88]print("Highest:", max(marks))print("Lowest:", min(marks))print("Total:", sum(marks))print("All passed:", all(mark >= 40 for mark in marks))Output:
Highest: 91Lowest: 68Total: 404All passed: True⸻
🔹 Checking if Any Student Failed
marks = [75, 82, 35, 91, 88]failed = any(mark < 40 for mark in marks)print(failed)Output:
True👉 At least one student scored below 40.
⸻
❌ Common Mistakes:
🚫 Confusing
any() with all()🚫 Using
sum() with non-numeric values🚫 Forgetting that
min() and max() work based on comparison⸻
✅ Summary:
✔
any() → at least one condition is True ✔ all() → every condition is True ✔ min() → smallest value ✔ max() → largest value ✔ sum() → total value🚀 These built-in functions are extremely useful when working with lists and other collections.
⸻
📢 Follow 👉 https://t.me/futurestack45 🔁 Share with friends to grow together 🚀
Telegram
FutureStack ☁️⚡
AI | Cloud | Coding | Tech Trends
Learn - Build - Grow ❤️
Job Updates: https://t.me/thinkcareers
Learn - Build - Grow ❤️
Job Updates: https://t.me/thinkcareers