Tech Python
239 subscribers
120 photos
10 files
179 links
Python Programming Hub | Learn & Master Python

Welcome to the perfect channel to learn Python Programming โ€” from beginner to advanced!

For promotions & collaborations:
techbywedcoder@gmail.com

Join now and accelerate your Python journey!
Download Telegram
๐Ÿ PYTHON โ€“ DAY 20 STUDY MATERIAL
โœจ Topic: Dictionary Methods & Nested Dictionary

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“Œ Important Dictionary Methods

๐Ÿ”น update() โ€“ Adds or updates key-value pairs

Example:
student = {"name": "Soham"}
student.update({"age": 21})

๐Ÿ”น get() โ€“ Returns value of key
print(student.get("name"))

๐Ÿ”น setdefault() โ€“ Returns value, adds key if not present
student.setdefault("city", "Pune")

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

โŒ Removing Dictionary Data

๐Ÿ”น del โ€“ Deletes key
del student["age"]

๐Ÿ”น clear() โ€“ Removes all data
student.clear()

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿงฉ Nested Dictionary

A dictionary inside another dictionary is called a nested dictionary.

Example:
students = {
1: {"name": "Amit", "age": 20},
2: {"name": "Soham", "age": 21}
}
Access nested value:
print(students[1]["name"])

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ” Loop Through Nested Dictionary

Example:
for id, info in students.items():
print(id, info["name"], info["age"])

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿงฎ Copy Dictionary

๐Ÿ”น copy() โ€“ Creates shallow copy
new_dict = student.copy()

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“ Practice Tasks โ€“ Day 20

โœ” Use update() and setdefault()
โœ” Create nested dictionary
โœ” Access and print nested values
โœ” Loop through nested dictionary

Example Program:
data = {1: {"name": "Raj", "marks": 80}}
print(data[1]["marks"])

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐ŸŽฏ Day 20 Goal
โœ” Master dictionary methods
โœ” Work with nested dictionaries

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“… Next Topic โ€“ Day 21
๐Ÿ”ฅ Revision + Practice (Week Review)
โœจ Stay Connected | Keep Coding
๐Ÿš€ TechByWebCoder
๐Ÿ PYTHON โ€“ DAY 21 STUDY MATERIAL
โœจ Topic: Revision + Practice (Week Review)

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“Œ Topics Covered (Day 1 โ€“ Day 20)

โœ” Python Introduction & Installation
โœ” Variables & Data Types
โœ” Operators
โœ” Conditional Statements
โœ” while Loop & for Loop
โœ” break, continue, pass
โœ” Pattern Programs
โœ” Functions & Arguments
โœ” Recursion
โœ” Strings & String Methods
โœ” Lists & List Methods
โœ” Tuples
โœ” Sets
โœ” Dictionaries & Nested Dictionary

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿง  Quick Revision Points

๐Ÿ”น Variables are dynamically typed
๐Ÿ”น Indentation is mandatory in Python
๐Ÿ”น Lists are mutable, tuples are immutable
๐Ÿ”น Sets store unique values
๐Ÿ”น Dictionaries store key-value pairs
๐Ÿ”น Functions reduce code repetition

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿงช Practice Programs โ€“ Day 21

1๏ธโƒฃ Check whether a number is even or odd

num = int(input("Enter number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

2๏ธโƒฃ Find sum of elements in a list

nums = [10, 20, 30]
print(sum(nums))

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

3๏ธโƒฃ Reverse a string

text = input("Enter string: ")
print(text[::-1])

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

4๏ธโƒฃ Count frequency using dictionary

text = "python"
freq = {}
for ch in text:
freq[ch] = freq.get(ch, 0) + 1
print(freq)

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

โญ Challenge Tasks

โœ” Print star pyramid
โœ” Create simple calculator using functions
โœ” Remove duplicates from list
โœ” Store student data using dictionary

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐ŸŽฏ Day 21 Goal
โœ” Revise all fundamentals
โœ” Identify weak topics
โœ” Build confidence in basics

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“… Next Topic โ€“ Day 22
๐Ÿ”ฅ File Handling in Python
โœจ Stay Connected | Keep Coding
๐Ÿš€ TechByWebCoder
๐Ÿ PYTHON โ€“ DAY 22 STUDY MATERIAL
โœจ Topic: File Handling in Python

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“Œ What is File Handling?

File handling allows Python programs to read data from files and write data to files permanently.

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“‚ Types of Files

โœ” Text files (.txt)
โœ” Binary files (.bin, .dat)

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“ Opening a File

Syntax:
file = open("filename", "mode")
Common modes:
"r" โ†’ Read
"w" โ†’ Write
"a" โ†’ Append
"x" โ†’ Create
"rb" โ†’ Read binary
"wb" โ†’ Write binary

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“– Reading from a File

Example:
file = open("data.txt", "r")
print(file.read())
file.close()

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

โœ๏ธ Writing to a File

Example:
file = open("data.txt", "w")
file.write("Hello Python")
file.close()

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

โž• Append Data to File

Example:
file = open("data.txt", "a")
file.write("\nWelcome")
file.close()

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”’ Using with Statement
Automatically closes the file.

Example:
with open("data.txt", "r") as file:
print(file.read())

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“ Practice Tasks โ€“ Day 22

โœ” Create a text file
โœ” Write data into file
โœ” Read file content
โœ” Append data to file

Example Program:
with open("test.txt", "w") as f:
f.write("Python File Handling")

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐ŸŽฏ Day 22 Goal
โœ” Understand file operations
โœ” Read & write files safely

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“… Next Topic โ€“ Day 23
๐Ÿ”ฅ File Methods & File Modes
โœจ Stay Connected | Keep Coding
๐Ÿš€ TechByWebCoder
Forwarded from TECH BY WEB CODER
30 Pattern In Python.pdf
5 MB
Important Web Development And Programming Language Related Project๐Ÿ”—

๐Ÿ‘‡๐Ÿป๐Ÿ‘‡๐Ÿป๐Ÿ‘‡๐Ÿป๐Ÿ‘‡๐Ÿป๐Ÿ‘‡๐Ÿป๐Ÿ‘‡๐Ÿป๐Ÿ‘‡๐Ÿป๐Ÿ‘‡๐Ÿป๐Ÿ‘‡๐Ÿป

Topic :- Top 30 Patterns in Python (Star, Alphabet, And Number)
๐Ÿ‘1
๐Ÿ PYTHON โ€“ DAY 23 STUDY MATERIAL
โœจ Topic: File Methods & File Modes

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“Œ File Modes in Python

๐Ÿ”น "r" โ€“ Read mode (file must exist)
๐Ÿ”น "w" โ€“ Write mode (creates new / overwrites file)
๐Ÿ”น "a" โ€“ Append mode (adds data at end)
๐Ÿ”น "x" โ€“ Create file (error if file exists)
๐Ÿ”น "r+" โ€“ Read + Write
๐Ÿ”น "w+" โ€“ Write + Read

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“– Important File Methods

๐Ÿ”น read() โ€“ Reads entire file
๐Ÿ”น readline() โ€“ Reads one line
๐Ÿ”น readlines() โ€“ Reads all lines as list

Example:
with open("data.txt", "r") as f:
print(f.readline())

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

โœ๏ธ Writing Multiple Lines

Example:
with open("data.txt", "w") as f:
f.writelines(["Python\n", "Java\n", "C\n"])

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“ File Cursor Position

๐Ÿ”น tell() โ€“ Returns current position
๐Ÿ”น seek() โ€“ Changes position

Example:
with open("data.txt", "r") as f:
print(f.tell())
f.seek(0)

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿงน Closing a File

๐Ÿ”น close() โ€“ Closes file manually
๐Ÿ”น with statement โ€“ Closes automatically (recommended)

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

โš ๏ธ Common File Errors

โŒ FileNotFoundError
โŒ PermissionError
โŒ Wrong mode usage

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“ Practice Tasks โ€“ Day 23

โœ” Read file line by line
โœ” Write multiple lines to file
โœ” Use tell() and seek()
โœ” Try different file modes

Example Program:
with open("demo.txt", "w+") as f:
f.write("Hello Python")
f.seek(0)
print(f.read())

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐ŸŽฏ Day 23 Goal
โœ” Master file modes
โœ” Use file methods confidently

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“… Next Topic โ€“ Day 24
๐Ÿ”ฅ Exception Handling (try, except)
โœจ Stay Connected | Keep Coding
๐Ÿš€ TechByWebCoder
๐Ÿ PYTHON โ€“ DAY 24 STUDY MATERIAL
โœจ Topic: Exception Handling in Python

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“Œ What is an Exception?

An exception is an error that occurs during program execution, which interrupts normal flow.
Examples:
ZeroDivisionError
ValueError
TypeError

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ›ก Why Use Exception Handling?

โœ” Prevent program crash
โœ” Handle errors gracefully
โœ” Improve program reliability

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น try-except Block

Syntax:
try:
risky_code
except:
error_handling_code

Example:
try:
x = int(input("Enter number: "))
print(10 / x)
except:
print("Error occurred")

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Handling Specific Exceptions

Example:
try:
print(10 / 0)
except ZeroDivisionError:
print("Cannot divide by zero")

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Multiple except Blocks

Example:
try:
x = int(input())
except ValueError:
print("Invalid input")
except ZeroDivisionError:
print("Division error")

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น else Block
Executes if no exception occurs.

Example:
try:
print(10 / 2)
except:
print("Error")
else:
print("Success")

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น finally Block
Always executes (used for cleanup).

Example:
try:
print(10 / 2)
finally:
print("Done")

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“ Practice Tasks โ€“ Day 24

โœ” Handle divide by zero
โœ” Handle invalid input
โœ” Use else and finally
โœ” Write safe calculator

Example Program:
try:
a = int(input("Enter a: "))
b = int(input("Enter b: "))
print(a / b)
except Exception as e:
print("Error:", e)

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐ŸŽฏ Day 24 Goal
โœ” Handle runtime errors
โœ” Write crash-free programs

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“… Next Topic โ€“ Day 25
๐Ÿ”ฅ User-Defined Exceptions
โœจ Stay Connected | Keep Coding
๐Ÿš€ TechByWebCoder
๐Ÿ PYTHON โ€“ DAY 25 STUDY MATERIAL
โœจ Topic: User-Defined Exceptions

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“Œ What is a User-Defined Exception?

User-defined exceptions are custom errors created by programmers to handle specific situations.

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿงฉ Why Use Custom Exceptions?

โœ” Clear error messages
โœ” Better control over program flow
โœ” Easy debugging

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Creating a Custom Exception

Custom exceptions are created by inheriting from Exception class.

Example:
class AgeError(Exception):
pass

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Raising a Custom Exception

Example:
def check_age(age):
if age < 18:
raise AgeError("Age must be 18 or above")
else:
print("Eligible")

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Handling Custom Exception

Example:
try:
check_age(16)
except AgeError as e:
print(e)

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Using raise Keyword

The raise keyword is used to trigger an exception manually.

Example:
raise ValueError("Invalid value")

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

โš ๏ธ Important Notes

โ€ข Custom exceptions should be meaningful
โ€ข Always handle raised exceptions
โ€ข Use inheritance properly

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“ Practice Tasks โ€“ Day 25

โœ” Create custom exception for login failure
โœ” Raise exception for invalid marks
โœ” Handle custom exception using try-except

Example Program:
class MarksError(Exception):
pass
marks = int(input("Enter marks: "))
if marks < 0 or marks > 100:
raise MarksError("Invalid marks")

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐ŸŽฏ Day 25 Goal
โœ” Understand custom exception creation
โœ” Handle program-specific errors

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“… Next Topic โ€“ Day 26
๐Ÿ”ฅ Modules in Python
โœจ Stay Connected | Keep Coding
๐Ÿš€ TechByWebCoder
๐Ÿ PYTHON โ€“ DAY 26 STUDY MATERIAL
โœจ Topic: Modules in Python

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“Œ What is a Module?

A module is a file containing Python code (functions, variables, classes) that can be reused in another program.
It helps in code reusability and organization.

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“ฆ Importing a Module

Syntax:
import module_name

Example:
import math
print(math.sqrt(25))

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Import Specific Function

Syntax:
from module_name import function_name

Example:
from math import sqrt
print(sqrt(16))

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Import with Alias

Example:
import math as m
print(m.pi)

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿงฎ Common Built-in Modules

๐Ÿ”น math โ€“ Mathematical operations
๐Ÿ”น random โ€“ Random number generation
๐Ÿ”น datetime โ€“ Date & time handling
๐Ÿ”น os โ€“ Operating system functions

Example (random):
import random
print(random.randint(1, 10))

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ›  Creating User-Defined Module

Step 1: Create file mymodule.py
def greet():
print("Hello from module")

Step 2: Import in another file
import mymodule
mymodule.greet()

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

โš ๏ธ Important Points

โ€ข Module file must be in same folder
โ€ข Avoid naming conflict with built-in modules
โ€ข Use alias for shorter names

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“ Practice Tasks โ€“ Day 26

โœ” Use math module
โœ” Generate random number
โœ” Create your own module
โœ” Import specific function

Example Program:
from random import randint
print(randint(1, 100))

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐ŸŽฏ Day 26 Goal
โœ” Understand module usage
โœ” Create reusable code files

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“… Next Topic โ€“ Day 27
๐Ÿ”ฅ OOP โ€“ Class & Object
โœจ Stay Connected | Keep Coding
๐Ÿš€ TechByWebCoder
๐Ÿ PYTHON โ€“ DAY 27 STUDY MATERIAL
โœจ Topic: OOP โ€“ Class & Object

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“Œ What is OOP?

OOP (Object Oriented Programming) is a programming concept based on objects and classes.

It helps in:
โœ” Code reusability
โœ” Data security
โœ” Real-world modeling

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿท What is a Class?
A class is a blueprint for creating objects.

Syntax:
class ClassName:
pass

Example:
class Student:
pass

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ‘ค What is an Object?
An object is an instance of a class.

Example:
s1 = Student()
Here, s1 is an object.

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Class with Attributes

Example:
class Student:
name = "Soham"
age = 20
obj = Student()
print(obj.name)

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น init Constructor Method

Used to initialize object data.

Example:
class Student:
def init(self, name, age):
self.name = name
self.age = age
s1 = Student("Rahul", 22)
print(s1.name)

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Instance Method

Example:
class Student:
def init(self, name):
self.name = name
def greet(self):
print("Hello", self.name)
s1 = Student("Amit")
s1.greet()

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿง  Understanding self Keyword

โ€ข self refers to the current object
โ€ข It must be the first parameter in class methods

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“ Practice Tasks โ€“ Day 27

โœ” Create class Car with attributes
โœ” Create object of Car
โœ” Use constructor
โœ” Create method inside class

Example Program:
class Car:
def init(self, brand):
self.brand = brand
def show(self):
print("Brand:", self.brand)
c1 = Car("BMW")
c1.show()

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐ŸŽฏ Day 27 Goal
โœ” Understand class & object
โœ” Use constructor and methods

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“… Next Topic โ€“ Day 28
๐Ÿ”ฅ OOP โ€“ Encapsulation
โœจ Stay Connected | Keep Coding
๐Ÿš€ TechByWebCoder
๐Ÿ PYTHON โ€“ DAY 28 STUDY MATERIAL
โœจ Topic: OOP โ€“ Encapsulation

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“Œ What is Encapsulation?
Encapsulation means binding data (variables) and methods (functions) together in a single unit (class) and restricting direct access to some data.

It helps in:
โœ” Data protection
โœ” Better security
โœ” Controlled access

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”’ Access Modifiers in Python

Python does not have strict private/public like other languages, but it follows naming conventions:

๐Ÿ”น Public โ†’ Accessible anywhere
๐Ÿ”น Protected โ†’ Single underscore (_)
๐Ÿ”น Private โ†’ Double underscore (__)

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Public Variable Example

class Student:
def init(self):
self.name = "Soham"
obj = Student()
print(obj.name)

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Protected Variable Example

class Student:
def init(self):
self._age = 20
obj = Student()
print(obj._age)
(Note: Still accessible, but should not be accessed directly)

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ” Private Variable Example

class Student:
def init(self):
self.__marks = 85
obj = Student()
print(obj.__marks) โŒ Error
To access private variable:
print(obj._Student__marks)

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Getter and Setter Methods
Used to access and modify private data safely.

Example:
class Student:
def init(self):
self.__marks = 0
def set_marks(self, m):
self.__marks = m

def get_marks(self):
return self.__marks
s1 = Student()
s1.set_marks(90)
print(s1.get_marks())

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“ Practice Tasks โ€“ Day 28

โœ” Create class with private variable
โœ” Create getter & setter
โœ” Try accessing private variable directly
โœ” Understand name mangling

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐ŸŽฏ Day 28 Goal
โœ” Understand data hiding
โœ” Use getter & setter properly

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“… Next Topic โ€“ Day 29
๐Ÿ”ฅ OOP โ€“ Inheritance
โœจ Stay Connected | Keep Coding
๐Ÿš€ TechByWebCoder
๐Ÿ PYTHON โ€“ DAY 29 STUDY MATERIAL
โœจ Topic: OOP โ€“ Inheritance

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“Œ What is Inheritance?

Inheritance allows one class to reuse the properties and methods of another class.

โœ” Code Reusability
โœ” Reduces redundancy
โœ” Improves maintainability
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ‘จโ€๐Ÿ‘ฆ Parent & Child Class

๐Ÿ”น Parent Class โ†’ Base Class
๐Ÿ”น Child Class โ†’ Derived Class

Syntax:
class Parent:
pass
class Child(Parent):
pass

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Basic Inheritance Example

class Person:
def greet(self):
print("Hello from Parent")
class Student(Person):
pass
s1 = Student()
s1.greet() # Inherited method

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Inheritance with Constructor

class Person:
def init(self, name):
self.name = name
class Student(Person):
def display(self):
print("Name:", self.name)
s1 = Student("Rahul")
s1.display()

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Using super() Function

Used to call parent class constructor.
class Person:
def init(self, name):
self.name = name
class Student(Person):
def init(self, name, age):
super().init(name)
self.age = age
def display(self):
print(self.name, self.age)
s1 = Student("Amit", 21)
s1.display()

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Types of Inheritance in Python

1๏ธโƒฃ Single Inheritance
2๏ธโƒฃ Multiple Inheritance
3๏ธโƒฃ Multilevel Inheritance
4๏ธโƒฃ Hierarchical Inheritance
5๏ธโƒฃ Hybrid Inheritance

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿง  Multilevel Inheritance Example

class A:
def methodA(self):
print("Class A")
class B(A):
def methodB(self):
print("Class B")
class C(B):
def methodC(self):
print("Class C")
obj = C()
obj.methodA()
obj.methodB()
obj.methodC()

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“ Practice Tasks โ€“ Day 29

โœ” Create Parent class Vehicle
โœ” Create Child class Car
โœ” Use super()
โœ” Try multilevel inheritance

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐ŸŽฏ Day 29 Goal
โœ” Understand Parent & Child relationship
โœ” Use super() correctly
โœ” Practice different inheritance types

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“… Next Topic โ€“ Day 30
๐Ÿ”ฅ OOP โ€“ Polymorphism
โœจ Stay Connected | Keep Coding
๐Ÿš€ TechByWebCoder
๐Ÿ PYTHON โ€“ DAY 30 STUDY MATERIAL
โœจ Topic: OOP โ€“ Polymorphism

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“Œ What is Polymorphism?

Polymorphism means โ€œmany formsโ€.
In Python, it allows the same function name to behave differently depending on the object.

โœ” Increases flexibility
โœ” Improves readability
โœ” Makes code scalable

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Method Overriding (Runtime Polymorphism)

When a child class provides a different implementation of a method from the parent class.

Example:
class Animal:
def sound(self):
print("Animal makes sound")
class Dog(Animal):
def sound(self):
print("Dog barks")
obj = Dog()
obj.sound()

Output:
Dog barks

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Polymorphism with Multiple Classes

class Cat:
def sound(self):
print("Meow")
class Dog:
def sound(self):
print("Bark")
def make_sound(animal):
animal.sound()
make_sound(Cat())
make_sound(Dog())
Same function โ†’ Different behavior

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Operator Overloading

Python allows operators to behave differently for different data types.

Example:
print(5 + 3) # 8
print("Hi " + "All") # Hi All
โ€œ+โ€ works for numbers and strings differently.

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Method Overloading in Python?

Python does NOT support traditional method overloading like Java.

But we can simulate it using default arguments:
class Calculator:
def add(self, a, b=0, c=0):
return a + b + c
obj = Calculator()
print(obj.add(5))
print(obj.add(5, 3))
print(obj.add(5, 3, 2))

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿง  Real Life Example

Think about a โ€œPaymentโ€ system:
โœ” Credit Card Payment
โœ” UPI Payment
โœ” Net Banking

All use a method like pay(), but the implementation is different.

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“ Practice Tasks โ€“ Day 30

โœ” Create class Shape with method area()
โœ” Override area() in Circle & Rectangle
โœ” Create common function to call area()

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐ŸŽฏ Day 30 Goal
โœ” Understand Method Overriding
โœ” Understand Dynamic Polymorphism
โœ” Practice real-life examples

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“… Next Topic โ€“ Day 31
๐Ÿ”ฅ OOP โ€“ Abstraction
โœจ Stay Connected | Keep Coding
๐Ÿš€ TechByWebCoder
๐Ÿ PYTHON โ€“ DAY 31 STUDY MATERIAL
โœจ Topic: OOP โ€“ Abstraction

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“Œ What is Abstraction?

Abstraction means hiding implementation details and showing only essential features.
Example in real life ๐Ÿš—
You drive a car without knowing how the engine works internally.

โœ” Hides complexity
โœ” Improves security
โœ” Focus on what, not how

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น How to Achieve Abstraction in Python?

Using the abc (Abstract Base Class) module
We import:
from abc import ABC, abstractmethod

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Creating an Abstract Class

Example:
from abc import ABC, abstractmethod
class Animal(ABC):
@abstractmethod
def sound(self):
pass
This class cannot be instantiated directly.

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Implementing Abstract Method in Child Class

from abc import ABC, abstractmethod
class Animal(ABC):
@abstractmethod
def sound(self):
pass
class Dog(Animal):
def sound(self):
print("Dog barks")
obj = Dog()
obj.sound()
If we donโ€™t implement sound(), it gives error โŒ

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Why Use Abstraction?

โœ” To enforce method implementation
โœ” To create standard structure
โœ” To design scalable applications

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿง  Real World Example

Payment System:
class Payment(ABC):
@abstractmethod
def pay(self):
pass
class UPI(Payment):
def pay(self):
print("Paid using UPI")
class Card(Payment):
def pay(self):
print("Paid using Card")

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“ Practice Tasks โ€“ Day 31

โœ” Create abstract class Shape
โœ” Create area() abstract method
โœ” Implement in Circle & Rectangle
โœ” Try creating object of abstract class (see error)

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐ŸŽฏ Day 31 Goal
โœ” Understand abstraction
โœ” Use abc module
โœ” Implement abstract methods

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“… Next Topic โ€“ Day 32
๐Ÿ”ฅ OOP โ€“ Special (Magic/Dunder) Methods
โœจ Stay Connected | Keep Coding
๐Ÿš€ TechByWebCoder
Forwarded from Tech by WebCoder
๐ŸŽ‰ ANNOUNCEMENT ๐ŸŽ‰

๐Ÿš€ TOP 10 LOGIN PAGE VIDEO CHALLENGE! ๐Ÿ”ฅ


HEY EVERYONE! ๐Ÿ‘‹

Iโ€™m super excited to announce a brand-new Login Page Design Challenge on my YouTube channel โ€œ TECHBYWEBCODER โ€!

๐Ÿ“… STARTING FROM: 22 FEBRUARY 2026

๐Ÿ•’ 1 LOGIN PAGE DESIGN EVERY DAY (FOR 10 DAYS)
๐Ÿ“Œ COVERING:
โœ… HTML, CSS & JavaScript
โœ… Modern & Responsive Login Pages
โœ… Glassmorphism & Neumorphism UI
โœ… Animated Login Forms
โœ… Password Show/Hide Feature
โœ… Validation & Error Messages
โœ… Beginner to Advanced Designs
โœ… Real Project Style Layouts
โœ… Clean Code + Full Explanation
โœ… Interview & Portfolio Ready Designs
Whether youโ€™re a beginner in web development or want to improve your UI design skills, this challenge will help you master login page creation step by step.

๐Ÿ”” SUBSCRIBE & TURN ON NOTIFICATIONS so you donโ€™t miss any challenge video!

๐Ÿ‘‰ https://yt.openinapp.co/nz63a

๐Ÿ’ฌ Letโ€™s build stunning login pages together and level up our web development skills โ€” one design at a time! ๐Ÿ’ป๐Ÿ”ฅ
๐Ÿ PYTHON โ€“ DAY 32 STUDY MATERIAL
โœจ Topic: OOP โ€“ Special (Magic / Dunder) Methods

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“Œ What are Magic (Dunder) Methods?

Magic methods are special methods that start and end with double underscores:

Example:
init
str
len

They allow us to define behavior for built-in operations.
โ€œDunderโ€ = Double Under ( __ )

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น init Method
Constructor method
Automatically called when object is created.

Example:
class Student:
def init(self, name):
self.name = name
s1 = Student("Rahul")

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น str Method

Used to define what gets printed when we print an object.

Example:
class Student:
def init(self, name):
self.name = name
def str(self):
return f"Student Name: {self.name}"
s1 = Student("Amit")
print(s1)
Without str โ†’ It prints object memory address
With str โ†’ Custom readable output โœ…

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น len Method
Defines behavior for len() function.

Example:
class MyList:
def init(self, items):
self.items = items
def len(self):
return len(self.items)
obj = MyList([1,2,3,4])
print(len(obj))

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Operator Overloading using Magic Methods

Example: add
class Number:
def init(self, value):
self.value = value
def add(self, other):
return self.value + other.value
n1 = Number(5)
n2 = Number(10)
print(n1 + n2)

Now + works for custom objects ๐Ÿ”ฅ

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Common Magic Methods

โœ” init โ†’ Constructor
โœ” str โ†’ String representation
โœ” len โ†’ Length
โœ” add โ†’ Addition
โœ” sub โ†’ Subtraction
โœ” mul โ†’ Multiplication
โœ” eq โ†’ Equality

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“ Practice Tasks โ€“ Day 32

โœ” Create class Book
โœ” Implement str
โœ” Overload + operator
โœ” Try implementing len

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐ŸŽฏ Day 32 Goal
โœ” Understand dunder methods
โœ” Customize built-in operations
โœ” Practice operator overloading

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“… Next Topic โ€“ Day 33
๐Ÿ”ฅ Exception Handling in Python
โœจ Stay Connected | Keep Coding
๐Ÿš€ TechByWebCoder
๐Ÿ PYTHON โ€“ DAY 33 STUDY MATERIAL
โœจ Topic: Exception Handling in Python

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“Œ What is Exception?
An exception is an error that occurs during program execution.

Examples:
โŒ Division by zero
โŒ Invalid input
โŒ File not found
Without handling โ†’ Program crashes
With handling โ†’ Program continues safely โœ…

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Basic try-except Syntax

try:
risky code
except:
handle error

Example:
try:
num = 10 / 0
except:
print("Error occurred!")

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Handling Specific Exceptions

try:
num = int(input("Enter number: "))
print(10 / num)
except ZeroDivisionError:
print("Cannot divide by zero")
except ValueError:
print("Invalid input")

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Using else Block
Runs if no exception occurs.

try:
num = int(input("Enter number: "))
except ValueError:
print("Invalid input")
else:
print("You entered:", num)

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Using finally Block
Always executes (whether error occurs or not).

try:
print(10 / 2)
except:
print("Error")
finally:
print("Execution completed")

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Raising Custom Exception
We can create our own error using raise.

Example:
age = 15
if age < 18:
raise ValueError("Age must be 18 or above")

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Creating Custom Exception Class

class MyError(Exception):
pass
raise MyError("Custom error occurred")

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿง  Why Exception Handling is Important?

โœ” Prevent program crash
โœ” Improve user experience
โœ” Handle unexpected situations
โœ” Make code professional

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“ Practice Tasks โ€“ Day 33

โœ” Handle ZeroDivisionError
โœ” Handle ValueError
โœ” Use finally block
โœ” Create custom exception

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐ŸŽฏ Day 33 Goal
โœ” Understand try-except
โœ” Handle multiple exceptions
โœ” Create custom errors

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“… Next Topic โ€“ Day 34
๐Ÿ”ฅ File Handling in Python
โœจ Stay Connected | Keep Coding
๐Ÿš€ TechByWebCoder
๐Ÿ PYTHON โ€“ DAY 34 STUDY MATERIAL
โœจ Topic: File Handling in Python

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“Œ What is File Handling?

File handling allows us to create, read, write, and update files.
โœ” Store data permanently
โœ” Read existing data
โœ” Modify data

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Opening a File

Syntax:
file = open("filename.txt", "mode")

Modes:
"r" โ†’ Read
"w" โ†’ Write (overwrites file)
"a" โ†’ Append
"x" โ†’ Create new file
"rb" โ†’ Read binary

Example:
file = open("demo.txt", "r")

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Reading a File

file = open("demo.txt", "r")
print(file.read())
file.close()
Other read methods:
file.readline()
file.readlines()

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Writing to a File

file = open("demo.txt", "w")
file.write("Hello Python")
file.close()

โš  "w" mode overwrites existing data.

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Appending to a File

file = open("demo.txt", "a")
file.write("\nNew Line Added")
file.close()

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Using with Statement (Best Practice)

Automatically closes file.
with open("demo.txt", "r") as file:
data = file.read()
print(data)
No need to call close() โœ…

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Checking if File Exists

import os
if os.path.exists("demo.txt"):
print("File exists")
else:
print("File not found")

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿง  Why File Handling is Important?

โœ” Store user data
โœ” Save reports
โœ” Manage logs
โœ” Work with databases & APIs

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“ Practice Tasks โ€“ Day 34

โœ” Create a file
โœ” Write your name into file
โœ” Append new line
โœ” Read entire file
โœ” Use with statement

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐ŸŽฏ Day 34 Goal
โœ” Understand file modes
โœ” Perform read & write operations
โœ” Use with statement

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“… Next Topic โ€“ Day 35
๐Ÿ”ฅ Working with CSV Files
โœจ Stay Connected | Keep Coding
๐Ÿš€ TechByWebCoder
๐Ÿ PYTHON โ€“ DAY 35 STUDY MATERIAL
โœจ Topic: Working with CSV Files in Python

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“Œ What is a CSV File?

CSV = Comma Separated Values
Used to store tabular data like:
โœ” Excel data
โœ” Student records
โœ” Sales reports

Example CSV file:
name,age,city
Rahul,22,Pune
Amit,21,Mumbai

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Importing CSV Module

Python provides built-in module:
import csv

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Reading CSV File

import csv
with open("data.csv", "r") as file:
reader = csv.reader(file)
for row in reader:
print(row)
Each row is returned as a list.

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Writing to CSV File

import csv
with open("data.csv", "w", newline="") as file:
writer = csv.writer(file)
writer.writerow(["Name", "Age", "City"])
writer.writerow(["Soham", 20, "Pune"])

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Appending Data to CSV

with open("data.csv", "a", newline="") as file:
writer = csv.writer(file)
writer.writerow(["Amit", 22, "Mumbai"])

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Using DictReader (Advanced Reading)

import csv
with open("data.csv", "r") as file:
reader = csv.DictReader(file)
for row in reader:
print(row["Name"], row["City"])
Reads CSV as dictionary ๐Ÿ”ฅ

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Using DictWriter

with open("data.csv", "w", newline="") as file:
fieldnames = ["Name", "Age"]
writer = csv.DictWriter(file, fieldnames=fieldnames)
writer.writeheader()
writer.writerow({"Name": "Rahul", "Age": 22})

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿง  Why CSV is Important?

โœ” Used in Data Science
โœ” Used in Excel integration
โœ” Used in reporting systems
โœ” Used in real-world projects

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“ Practice Tasks โ€“ Day 35

โœ” Create student.csv file
โœ” Add 5 student records
โœ” Read and print specific column
โœ” Use DictReader

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐ŸŽฏ Day 35 Goal
โœ” Understand CSV module
โœ” Perform read & write operations
โœ” Work with structured data

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“… Next Topic โ€“ Day 36
๐Ÿ”ฅ Working with JSON in Python
โœจ Stay Connected | Keep Coding
๐Ÿš€ TechByWebCoder
๐Ÿ PYTHON โ€“ DAY 36 STUDY MATERIAL
โœจ Topic: Working with JSON in Python

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“Œ What is JSON?

JSON = JavaScript Object Notation
โœ” Lightweight data format
โœ” Used in APIs
โœ” Used in Web & Mobile Apps
โœ” Human readable

Example JSON:
{ "name": "Soham", "age": 20, "city": "Pune" }

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”
๐Ÿ”น Import JSON Module

Python provides built-in module:
import json

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Convert Python โ†’ JSON (Serialization)

import json
data = { "name": "Rahul", "age": 22 }
json_data = json.dumps(data)
print(json_data)
dumps() โ†’ Convert dictionary to JSON string

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Convert JSON โ†’ Python (Deserialization)

import json
json_string = '{"name": "Amit", "age": 21}'
data = json.loads(json_string)
print(data["name"])
loads() โ†’ Convert JSON string to dictionary

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Writing JSON to File

import json
data = {"name": "Soham", "age": 20}
with open("data.json", "w") as file:
json.dump(data, file)
dump() โ†’ Write JSON to file

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Reading JSON from File

import json
with open("data.json", "r") as file:
data = json.load(file)
print(data)
load() โ†’ Read JSON from file

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Pretty Printing JSON

print(json.dumps(data, indent=4))
indent โ†’ Makes JSON readable

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿง  Why JSON is Important?

โœ” Used in REST APIs
โœ” Used in Web Development
โœ” Used in Data Exchange
โœ” Used in Backend Systems

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“ Practice Tasks โ€“ Day 36

โœ” Create dictionary
โœ” Convert to JSON
โœ” Save in file
โœ” Read from file
โœ” Pretty print output

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐ŸŽฏ Day 36 Goal
โœ” Understand serialization & deserialization
โœ” Work with JSON files
โœ” Prepare for API integration

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“… Next Topic โ€“ Day 37
๐Ÿ”ฅ Modules & Packages in Python
โœจ Stay Connected | Keep Coding
๐Ÿš€ TechByWebCoder
๐Ÿ PYTHON โ€“ DAY 37 STUDY MATERIAL
โœจ Topic: Modules & Packages in Python

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“Œ What is a Module?

A module is a Python file (.py) containing functions, variables, or classes.

โœ” Helps organize code
โœ” Enables code reuse
โœ” Improves readability

Example:
math.py โ†’ custom module

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Using Built-in Modules

Python provides many built-in modules:
โœ” math
โœ” random
โœ” datetime
โœ” os
โœ” sys

Example:
import math
print(math.sqrt(16))
print(math.pi)

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Importing Specific Function
from math import sqrt
print(sqrt(25))

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Import with Alias
import math as m
print(m.pi)

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Creating Your Own Module

Step 1: Create file mymodule.py
def greet(name):
print("Hello", name)

Step 2: Use it in another file
import mymodule
mymodule.greet("Soham")

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“ฆ What is a Package?

A package is a folder containing multiple modules.
It must contain a special file:
init.py

Example structure:

mypackage/
โ”‚โ”€โ”€ init.py
โ”‚โ”€โ”€ module1.py
โ”‚โ”€โ”€ module2.py

Import example:
from mypackage import module1

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Using name Variable

Every Python file has a special variable:
print(name)
If file is run directly โ†’ main
If imported โ†’ module name

Example:
if name == "main":
print("Run directly")

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿง  Why Modules & Packages?

โœ” Large project management
โœ” Code reusability
โœ” Professional coding practice
โœ” Used in real-world applications

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“ Practice Tasks โ€“ Day 37

โœ” Use math module
โœ” Create custom module
โœ” Import with alias
โœ” Create simple package

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐ŸŽฏ Day 37 Goal
โœ” Understand modular programming
โœ” Create and use custom modules
โœ” Understand package structure

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“… Next Topic โ€“ Day 38
๐Ÿ”ฅ Virtual Environment & pip
โœจ Stay Connected | Keep Coding
๐Ÿš€ TechByWebCoder