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 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
🐍 PYTHON – DAY 38 STUDY MATERIAL
Topic: Virtual Environment & pip

━━━━━━━━━━━━━━━━━━━

📌 What is pip?

pip is Python’s package manager.

It is used to:
Install packages
Upgrade packages
Remove packages
Manage project dependencies
Check pip version:
pip --version

━━━━━━━━━━━━━━━━━━━
🔹 Installing a Package

Example:
pip install requests
Install specific version:
pip install requests==2.31.0

━━━━━━━━━━━━━━━━━━━
🔹 Upgrading a Package

pip install --upgrade requests

━━━━━━━━━━━━━━━━━━━
🔹 Uninstalling a Package

pip uninstall requests

━━━━━━━━━━━━━━━━━━━
📦 What is Virtual Environment?

A virtual environment creates an isolated Python environment for each project.

Why important?

Avoid version conflicts
Separate project dependencies
Professional development practice

━━━━━━━━━━━━━━━━━━━

🔹 Creating Virtual Environment

Step 1:
python -m venv myenv

Step 2: Activate it
Windows:
myenv\Scripts\activate
Mac/Linux:
source myenv/bin/activate
After activation → (myenv) will appear in terminal

━━━━━━━━━━━━━━━━━━━

🔹 Deactivating Virtual Environment
deactivate


━━━━━━━━━━━━━━━━━━━

🔹 requirements.txt File
Used to store project dependencies.

Create file:
pip freeze > requirements.txt
Install from file:
pip install -r requirements.txt

━━━━━━━━━━━━━━━━━━━

🧠 Why This is Important?

Used in real-world projects
Required in Django/Flask
Required for deployment
Used in teamwork

━━━━━━━━━━━━━━━━━━━

📝 Practice Tasks – Day 38

Create virtual environment
Install any package
Freeze requirements
Deactivate environment

━━━━━━━━━━━━━━━━━━━

🎯 Day 38 Goal
Understand pip
Create virtual environment
Manage dependencies professionally

━━━━━━━━━━━━━━━━━━━

📅 Next Topic – Day 39
🔥 Introduction to Web Requests & APIs
Stay Connected | Keep Coding
🚀 TechByWebCoder