π 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
β¨ 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
β¨ 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
β¨ 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
β¨ 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
β¨ 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! π»π₯
π 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
β¨ 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
β¨ 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
β¨ 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
β¨ 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
β¨ 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
β¨ 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
β¨ 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
π PYTHON β DAY 39 STUDY MATERIAL
β¨ Topic: Introduction to Web Requests & APIs
βββββββββββββββββββ
π What is an API?
API = Application Programming Interface
It allows applications to communicate with each other.
Example:
β Weather App β Gets data from weather
API
β Payment App β Connects to bank server
β Instagram β Connects to backend server
βββββββββββββββββββ
π What is HTTP Request?
When your program communicates with a server, it sends:
β GET β Fetch data
β POST β Send data
β PUT β Update data
β DELETE β Remove data
βββββββββββββββββββ
π¦ Using requests Library
First install:
pip install requests
Then import:
import requests
βββββββββββββββββββ
πΉ Making a GET Request
import requests
response = requests.get("https://api.github.comοΏ½")
print(response.status_code)
print(response.text)
βββββββββββββββββββ
πΉ Getting JSON Response
import requests
response = requests.get("https://api.github.comοΏ½")
data = response.json()
print(data)
.json() converts response into dictionary π₯
βββββββββββββββββββ
πΉ Making a POST Request
import requests
data = {"name": "Soham"}
response = requests.post("https://httpbin.org/postοΏ½", json=data)
print(response.json())
βββββββββββββββββββ
πΉ Checking Response Status
200 β Success β
404 β Not Found β
500 β Server Error β
Example:
if response.status_code == 200:
print("Request successful")
βββββββββββββββββββ
π§ Why APIs Are Important?
β Used in Web Development
β Used in Mobile Apps
β Used in Automation
β Used in Data Science
βββββββββββββββββββ
π Practice Tasks β Day 39
β Install requests
β Make GET request
β Print JSON response
β Check status code
β Try POST request
βββββββββββββββββββ
π― Day 39 Goal
β Understand API concept
β Make HTTP requests
β Work with JSON responses aa
βββββββββββββββββββ
π Next Topic β Day 40
π₯ Mini Project β Weather App using API
β¨ Stay Connected | Keep Coding
π TechByWebCoder
β¨ Topic: Introduction to Web Requests & APIs
βββββββββββββββββββ
π What is an API?
API = Application Programming Interface
It allows applications to communicate with each other.
Example:
β Weather App β Gets data from weather
API
β Payment App β Connects to bank server
β Instagram β Connects to backend server
βββββββββββββββββββ
π What is HTTP Request?
When your program communicates with a server, it sends:
β GET β Fetch data
β POST β Send data
β PUT β Update data
β DELETE β Remove data
βββββββββββββββββββ
π¦ Using requests Library
First install:
pip install requests
Then import:
import requests
βββββββββββββββββββ
πΉ Making a GET Request
import requests
response = requests.get("https://api.github.comοΏ½")
print(response.status_code)
print(response.text)
βββββββββββββββββββ
πΉ Getting JSON Response
import requests
response = requests.get("https://api.github.comοΏ½")
data = response.json()
print(data)
.json() converts response into dictionary π₯
βββββββββββββββββββ
πΉ Making a POST Request
import requests
data = {"name": "Soham"}
response = requests.post("https://httpbin.org/postοΏ½", json=data)
print(response.json())
βββββββββββββββββββ
πΉ Checking Response Status
200 β Success β
404 β Not Found β
500 β Server Error β
Example:
if response.status_code == 200:
print("Request successful")
βββββββββββββββββββ
π§ Why APIs Are Important?
β Used in Web Development
β Used in Mobile Apps
β Used in Automation
β Used in Data Science
βββββββββββββββββββ
π Practice Tasks β Day 39
β Install requests
β Make GET request
β Print JSON response
β Check status code
β Try POST request
βββββββββββββββββββ
π― Day 39 Goal
β Understand API concept
β Make HTTP requests
β Work with JSON responses aa
βββββββββββββββββββ
π Next Topic β Day 40
π₯ Mini Project β Weather App using API
β¨ Stay Connected | Keep Coding
π TechByWebCoder
π PYTHON β DAY 40 STUDY MATERIAL
β¨ Mini Project: Weather App using API
βββββββββββββββββββ
π Project Goal
Create a simple Weather App that:
β Takes city name as input
β Fetches weather data from API
β Displays temperature & condition
Real-world concept:
API Integration + JSON Handling + User Input
βββββββββββββββββββ
π Step 1: Install Required Library
pip install requests
βββββββββββββββββββ
π Step 2: Get API Key
You can use free weather API like:
https://openweathermap.orgβ οΏ½
(Create free account β Generate API key)
βββββββββββββββββββ
π§ Step 3: Basic Weather App Code
import requests
api_key = "YOUR_API_KEY"
city = input("Enter city name: ")
url = f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}&units=metric"
response = requests.get(url)
data = response.json()
if response.status_code == 200:
temp = data["main"]["temp"]
desc = data["weather"][0]["description"]
print("City:", city)
print("Temperature:", temp, "Β°C")
print("Condition:", desc)
else:
print("City not found β")
βββββββββββββββββββ
π How It Works?
β User enters city
β API sends request
β Server returns JSON
β Python extracts temperature & description
βββββββββββββββββββ
π Error Handling Improvement
Add try-except:
try:
response = requests.get(url)
data = response.json()
except Exception as e:
print("Error:", e)
βββββββββββββββββββ
π¨ Bonus Improvements
β Add emoji based on weather βπ§β
β Use formatted output
β Add loop for multiple searches
β Add GUI using Tkinter
βββββββββββββββββββ
π Practice Tasks β Day 40
β Create weather app
β Handle invalid city
β Add loop option
β Improve output formatting
βββββββββββββββββββ
π― Day 40 Goal
β Integrate API
β Handle JSON
β Build mini project
βββββββββββββββββββ
π Next Topic β Day 41
π₯ Introduction to Tkinter (GUI Programming)
β¨ Stay Connected | Keep Coding
π TechByWebCoder
β¨ Mini Project: Weather App using API
βββββββββββββββββββ
π Project Goal
Create a simple Weather App that:
β Takes city name as input
β Fetches weather data from API
β Displays temperature & condition
Real-world concept:
API Integration + JSON Handling + User Input
βββββββββββββββββββ
π Step 1: Install Required Library
pip install requests
βββββββββββββββββββ
π Step 2: Get API Key
You can use free weather API like:
https://openweathermap.orgβ οΏ½
(Create free account β Generate API key)
βββββββββββββββββββ
π§ Step 3: Basic Weather App Code
import requests
api_key = "YOUR_API_KEY"
city = input("Enter city name: ")
url = f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}&units=metric"
response = requests.get(url)
data = response.json()
if response.status_code == 200:
temp = data["main"]["temp"]
desc = data["weather"][0]["description"]
print("City:", city)
print("Temperature:", temp, "Β°C")
print("Condition:", desc)
else:
print("City not found β")
βββββββββββββββββββ
π How It Works?
β User enters city
β API sends request
β Server returns JSON
β Python extracts temperature & description
βββββββββββββββββββ
π Error Handling Improvement
Add try-except:
try:
response = requests.get(url)
data = response.json()
except Exception as e:
print("Error:", e)
βββββββββββββββββββ
π¨ Bonus Improvements
β Add emoji based on weather βπ§β
β Use formatted output
β Add loop for multiple searches
β Add GUI using Tkinter
βββββββββββββββββββ
π Practice Tasks β Day 40
β Create weather app
β Handle invalid city
β Add loop option
β Improve output formatting
βββββββββββββββββββ
π― Day 40 Goal
β Integrate API
β Handle JSON
β Build mini project
βββββββββββββββββββ
π Next Topic β Day 41
π₯ Introduction to Tkinter (GUI Programming)
β¨ Stay Connected | Keep Coding
π TechByWebCoder
π PYTHON β DAY 41 STUDY MATERIAL
β¨ Topic: Introduction to Tkinter (GUI Programming)
βββββββββββββββββββ
π What is Tkinter?
Tkinter is Pythonβs built-in GUI (Graphical User Interface) library.
It allows you to create:
β Desktop Applications
β Forms
β Buttons & Labels
β Mini Software Projects
No installation required β (Built-in with Python)
βββββββββββββββββββ
π₯οΈ Creating First GUI Window
import tkinter as tk
root = tk.Tk()
root.title("My First App")
root.geometry("400x300")
root.mainloop()
This creates a simple window π₯
βββββββββββββββββββ
πΉ Adding a Label
import tkinter as tk
root = tk.Tk()
label = tk.Label(root, text="Hello Python GUI")
label.pack()
root.mainloop()
βββββββββββββββββββ
πΉ Adding a Button
import tkinter as tk
def click():
print("Button Clicked!")
root = tk.Tk()
btn = tk.Button(root, text="Click Me", command=click)
btn.pack()
root.mainloop()
βββββββββββββββββββ
πΉ Adding Entry (Input Box)
import tkinter as tk
def show():
print(entry.get())
root = tk.Tk()
entry = tk.Entry(root)
entry.pack()
btn = tk.Button(root, text="Submit", command=show)
btn.pack()
root.mainloop()
βββββββββββββββββββ
π Layout Methods
β pack() β Simple layout
β grid() β Table layout
β place() β Custom position
Example (grid):
label.grid(row=0, column=0)
βββββββββββββββββββ
π§ Why Tkinter?
β Build Desktop Apps
β Create Login Forms
β Build Calculator
β Create Management Systems
βββββββββββββββββββ
π Practice Tasks β Day 41
β Create window
β Add label
β Add button
β Take user input
β Try grid layout
βββββββββββββββββββ
π― Day 41 Goal
β Create basic GUI
β Add widgets
β Understand event handling
ββββββββββββββββββ
π Next Topic β Day 42
π₯ Building Calculator using Tkinter
β¨ Stay Connected | Keep Coding
π TechByWebCoder
β¨ Topic: Introduction to Tkinter (GUI Programming)
βββββββββββββββββββ
π What is Tkinter?
Tkinter is Pythonβs built-in GUI (Graphical User Interface) library.
It allows you to create:
β Desktop Applications
β Forms
β Buttons & Labels
β Mini Software Projects
No installation required β (Built-in with Python)
βββββββββββββββββββ
π₯οΈ Creating First GUI Window
import tkinter as tk
root = tk.Tk()
root.title("My First App")
root.geometry("400x300")
root.mainloop()
This creates a simple window π₯
βββββββββββββββββββ
πΉ Adding a Label
import tkinter as tk
root = tk.Tk()
label = tk.Label(root, text="Hello Python GUI")
label.pack()
root.mainloop()
βββββββββββββββββββ
πΉ Adding a Button
import tkinter as tk
def click():
print("Button Clicked!")
root = tk.Tk()
btn = tk.Button(root, text="Click Me", command=click)
btn.pack()
root.mainloop()
βββββββββββββββββββ
πΉ Adding Entry (Input Box)
import tkinter as tk
def show():
print(entry.get())
root = tk.Tk()
entry = tk.Entry(root)
entry.pack()
btn = tk.Button(root, text="Submit", command=show)
btn.pack()
root.mainloop()
βββββββββββββββββββ
π Layout Methods
β pack() β Simple layout
β grid() β Table layout
β place() β Custom position
Example (grid):
label.grid(row=0, column=0)
βββββββββββββββββββ
π§ Why Tkinter?
β Build Desktop Apps
β Create Login Forms
β Build Calculator
β Create Management Systems
βββββββββββββββββββ
π Practice Tasks β Day 41
β Create window
β Add label
β Add button
β Take user input
β Try grid layout
βββββββββββββββββββ
π― Day 41 Goal
β Create basic GUI
β Add widgets
β Understand event handling
ββββββββββββββββββ
π Next Topic β Day 42
π₯ Building Calculator using Tkinter
β¨ Stay Connected | Keep Coding
π TechByWebCoder
π PYTHON β DAY 42 STUDY MATERIAL
β¨ Mini Project: Calculator using Tkinter
βββββββββββββββββββ
π Project Goal
Create a simple calculator that:
β Takes two numbers
β Performs addition, subtraction, multiplication, division
β Displays result on screen
Concepts Used:
β Tkinter GUI
β Functions
β Event Handling
βββββββββββββββββββ
π₯οΈ Basic Calculator Code
import tkinter as tk
def calculate(operation):
num1 = float(entry1.get())
num2 = float(entry2.get())
if operation == "+":
result = num1 + num2
elif operation == "-":
result = num1 - num2
elif operation == "*":
result = num1 * num2
elif operation == "/":
result = num1 / num2
result_label.config(text="Result: " + str(result))
root = tk.Tk()
root.title("Calculator")
root.geometry("300x250")
tk.Label(root, text="Enter First Number").pack()
entry1 = tk.Entry(root)
entry1.pack()
tk.Label(root, text="Enter Second Number").pack()
entry2 = tk.Entry(root)
entry2.pack()
tk.Button(root, text="Add", command=lambda: calculate("+")).pack()
tk.Button(root, text="Subtract", command=lambda: calculate("-")).pack()
tk.Button(root, text="Multiply", command=lambda: calculate("*")).pack()
tk.Button(root, text="Divide", command=lambda: calculate("/")).pack()
result_label = tk.Label(root, text="Result: ")
result_label.pack()
root.mainloop()
βββββββββββββββββββ
β Improvement: Add Error Handling
Add try-except inside calculate():
try:
num1 = float(entry1.get())
num2 = float(entry2.get())
except ValueError:
result_label.config(text="Invalid Input β")
βββββββββββββββββββ
π¨ Bonus Improvements
β Add clear button
β Use grid layout
β Add better UI design
β Add keyboard support
ββββββββββββββββββ
π Practice Tasks β Day 42
β Build calculator
β Add error handling
β Improve UI
β Add clear button
βββββββββββββββββββ
π― Day 42 Goal
β Build complete GUI project
β Use functions with buttons
β Handle user input errors
βββββββββββββββββββ
π Next Topic β Day 43
π₯ Introduction to SQLite Database in Python
β¨ Stay Connected | Keep Coding
π TechByWebCoder
β¨ Mini Project: Calculator using Tkinter
βββββββββββββββββββ
π Project Goal
Create a simple calculator that:
β Takes two numbers
β Performs addition, subtraction, multiplication, division
β Displays result on screen
Concepts Used:
β Tkinter GUI
β Functions
β Event Handling
βββββββββββββββββββ
π₯οΈ Basic Calculator Code
import tkinter as tk
def calculate(operation):
num1 = float(entry1.get())
num2 = float(entry2.get())
if operation == "+":
result = num1 + num2
elif operation == "-":
result = num1 - num2
elif operation == "*":
result = num1 * num2
elif operation == "/":
result = num1 / num2
result_label.config(text="Result: " + str(result))
root = tk.Tk()
root.title("Calculator")
root.geometry("300x250")
tk.Label(root, text="Enter First Number").pack()
entry1 = tk.Entry(root)
entry1.pack()
tk.Label(root, text="Enter Second Number").pack()
entry2 = tk.Entry(root)
entry2.pack()
tk.Button(root, text="Add", command=lambda: calculate("+")).pack()
tk.Button(root, text="Subtract", command=lambda: calculate("-")).pack()
tk.Button(root, text="Multiply", command=lambda: calculate("*")).pack()
tk.Button(root, text="Divide", command=lambda: calculate("/")).pack()
result_label = tk.Label(root, text="Result: ")
result_label.pack()
root.mainloop()
βββββββββββββββββββ
β Improvement: Add Error Handling
Add try-except inside calculate():
try:
num1 = float(entry1.get())
num2 = float(entry2.get())
except ValueError:
result_label.config(text="Invalid Input β")
βββββββββββββββββββ
π¨ Bonus Improvements
β Add clear button
β Use grid layout
β Add better UI design
β Add keyboard support
ββββββββββββββββββ
π Practice Tasks β Day 42
β Build calculator
β Add error handling
β Improve UI
β Add clear button
βββββββββββββββββββ
π― Day 42 Goal
β Build complete GUI project
β Use functions with buttons
β Handle user input errors
βββββββββββββββββββ
π Next Topic β Day 43
π₯ Introduction to SQLite Database in Python
β¨ Stay Connected | Keep Coding
π TechByWebCoder
π PYTHON β DAY 43 STUDY MATERIAL
β¨ Topic: Introduction to SQLite Database in Python
βββββββββββββββββββ
π What is SQLite?
SQLite is a lightweight database that is stored in a single file.
β No server required
β Built into Python
β Perfect for small applications
Used in:
π± Mobile apps
π» Desktop apps
π§ Prototyping databases
βββββββββββββββββββ
πΉ Import SQLite Module
SQLite comes built-in with Python.
import sqlite3
βββββββββββββββββββ
πΉ Creating a Database
import sqlite3
conn = sqlite3.connect("student.db")
print("Database created successfully")
This creates a file student.db
βββββββββββββββββββ
πΉ Creating a Table
import sqlite3
conn = sqlite3.connect("student.db")
cursor = conn.cursor()
cursor.execute(""" CREATE TABLE student( id INTEGER PRIMARY KEY, name TEXT, age INTEGER ) """)
conn.commit()
conn.close()
βββββββββββββββββββ
πΉ Inserting Data
import sqlite3
conn = sqlite3.connect("student.db")
cursor = conn.cursor()
cursor.execute("INSERT INTO student VALUES(1,'Soham',20)")
conn.commit()
conn.close()
βββββββββββββββββββ
πΉ Reading Data
conn = sqlite3.connect("student.db")
cursor = conn.cursor()
cursor.execute("SELECT * FROM student")
rows = cursor.fetchall()
for row in rows:
print(row)
βββββββββββββββββββ
πΉ Updating Data
cursor.execute( "UPDATE student SET age=21 WHERE id=1"
βββββββββββββββββββ
πΉ Deleting Data
cursor.execute( "DELETE FROM student WHERE id=1" )
βββββββββββββββββββ
π§ Why SQLite is Useful?
β Build small database applications
β Store app data locally
β Practice SQL with Python
βββββββββββββββββββ
π Practice Tasks β Day 43
β Create database file
β Create student table
β Insert 3 records
β Display all records
β Update a record
βββββββββββββββββββ
π― Day 43 Goal
β Connect Python with database
β Perform CRUD operations
β Understand cursor & commit
βββββββββββββββββββ
π Next Topic β Day 44
π₯ Building Student Management System with SQLite
β¨ Stay Connected | Keep Coding
π TechByWebCoder
β¨ Topic: Introduction to SQLite Database in Python
βββββββββββββββββββ
π What is SQLite?
SQLite is a lightweight database that is stored in a single file.
β No server required
β Built into Python
β Perfect for small applications
Used in:
π± Mobile apps
π» Desktop apps
π§ Prototyping databases
βββββββββββββββββββ
πΉ Import SQLite Module
SQLite comes built-in with Python.
import sqlite3
βββββββββββββββββββ
πΉ Creating a Database
import sqlite3
conn = sqlite3.connect("student.db")
print("Database created successfully")
This creates a file student.db
βββββββββββββββββββ
πΉ Creating a Table
import sqlite3
conn = sqlite3.connect("student.db")
cursor = conn.cursor()
cursor.execute(""" CREATE TABLE student( id INTEGER PRIMARY KEY, name TEXT, age INTEGER ) """)
conn.commit()
conn.close()
βββββββββββββββββββ
πΉ Inserting Data
import sqlite3
conn = sqlite3.connect("student.db")
cursor = conn.cursor()
cursor.execute("INSERT INTO student VALUES(1,'Soham',20)")
conn.commit()
conn.close()
βββββββββββββββββββ
πΉ Reading Data
conn = sqlite3.connect("student.db")
cursor = conn.cursor()
cursor.execute("SELECT * FROM student")
rows = cursor.fetchall()
for row in rows:
print(row)
βββββββββββββββββββ
πΉ Updating Data
cursor.execute( "UPDATE student SET age=21 WHERE id=1"
βββββββββββββββββββ
πΉ Deleting Data
cursor.execute( "DELETE FROM student WHERE id=1" )
βββββββββββββββββββ
π§ Why SQLite is Useful?
β Build small database applications
β Store app data locally
β Practice SQL with Python
βββββββββββββββββββ
π Practice Tasks β Day 43
β Create database file
β Create student table
β Insert 3 records
β Display all records
β Update a record
βββββββββββββββββββ
π― Day 43 Goal
β Connect Python with database
β Perform CRUD operations
β Understand cursor & commit
βββββββββββββββββββ
π Next Topic β Day 44
π₯ Building Student Management System with SQLite
β¨ Stay Connected | Keep Coding
π TechByWebCoder
π PYTHON β DAY 44 STUDY MATERIAL
β¨ Mini Project: Student Management System using SQLite
βββββββββββββββββββ
π Project Goal
Create a simple Student Management System that can:
β Add student record
β View student records
β Update student details
β Delete student record
Concepts Used:
β SQLite Database
β CRUD Operations
β Python Functions
βββββββββββββββββββ
π Step 1: Create Database & Table
import sqlite3
conn = sqlite3.connect("student.db")
cursor = conn.cursor()
cursor.execute(""" CREATE TABLE IF NOT EXISTS student( id INTEGER PRIMARY KEY, name TEXT, age INTEGER, course TEXT ) """)
conn.commit()
βββββββββββββββββββ
β Step 2: Insert Student Data
def add_student(id, name, age, course):
cursor.execute( "INSERT INTO student VALUES(?,?,?,?)", (id, name, age, course) )
conn.commit()
Example:
add_student(1,"Soham",20,"Python")
βββββββββββββββββββ
π Step 3: View Students
def view_students():
cursor.execute("SELECT * FROM student")
rows = cursor.fetchall()
for row in rows:
print(row)
βββββββββββββββββββ
β Step 4: Update Student
def update_student(id, age):
cursor.execute( "UPDATE student SET age=? WHERE id=?", (age,id) )
conn.commit()
βββββββββββββββββββ
β Step 5: Delete Student
def delete_student(id):
cursor.execute( "DELETE FROM student WHERE id=?", (id,) )
conn.commit()
βββββββββββββββββββ
π§ How the System Works?
1οΈβ£ User adds student
2οΈβ£ Data stored in database
3οΈβ£ User can view/update/delete records
Real-world concept:
β Database CRUD operations
βββββββββββββββββββ
π¨ Bonus Improvements
β Add menu system
β Add input validation
β Connect with Tkinter GUI
β Export data to CSV
βββββββββββββββββββ
π Practice Tasks β Day 44
β Create student database
β Insert 5 students
β Display all records
β Update one record
β Delete one record
βββββββββββββββββββ
π― Day 44 Goal
β Build database project
β Understand CRUD operations
β Use SQLite with Python
βββββββββββββββββββ
π Next Topic β Day 45
π₯ Web Scraping using Python (BeautifulSoup)
β¨ Stay Connected | Keep Coding
π TechByWebCoder
β¨ Mini Project: Student Management System using SQLite
βββββββββββββββββββ
π Project Goal
Create a simple Student Management System that can:
β Add student record
β View student records
β Update student details
β Delete student record
Concepts Used:
β SQLite Database
β CRUD Operations
β Python Functions
βββββββββββββββββββ
π Step 1: Create Database & Table
import sqlite3
conn = sqlite3.connect("student.db")
cursor = conn.cursor()
cursor.execute(""" CREATE TABLE IF NOT EXISTS student( id INTEGER PRIMARY KEY, name TEXT, age INTEGER, course TEXT ) """)
conn.commit()
βββββββββββββββββββ
β Step 2: Insert Student Data
def add_student(id, name, age, course):
cursor.execute( "INSERT INTO student VALUES(?,?,?,?)", (id, name, age, course) )
conn.commit()
Example:
add_student(1,"Soham",20,"Python")
βββββββββββββββββββ
π Step 3: View Students
def view_students():
cursor.execute("SELECT * FROM student")
rows = cursor.fetchall()
for row in rows:
print(row)
βββββββββββββββββββ
β Step 4: Update Student
def update_student(id, age):
cursor.execute( "UPDATE student SET age=? WHERE id=?", (age,id) )
conn.commit()
βββββββββββββββββββ
β Step 5: Delete Student
def delete_student(id):
cursor.execute( "DELETE FROM student WHERE id=?", (id,) )
conn.commit()
βββββββββββββββββββ
π§ How the System Works?
1οΈβ£ User adds student
2οΈβ£ Data stored in database
3οΈβ£ User can view/update/delete records
Real-world concept:
β Database CRUD operations
βββββββββββββββββββ
π¨ Bonus Improvements
β Add menu system
β Add input validation
β Connect with Tkinter GUI
β Export data to CSV
βββββββββββββββββββ
π Practice Tasks β Day 44
β Create student database
β Insert 5 students
β Display all records
β Update one record
β Delete one record
βββββββββββββββββββ
π― Day 44 Goal
β Build database project
β Understand CRUD operations
β Use SQLite with Python
βββββββββββββββββββ
π Next Topic β Day 45
π₯ Web Scraping using Python (BeautifulSoup)
β¨ Stay Connected | Keep Coding
π TechByWebCoder
π PYTHON β DAY 45 STUDY MATERIAL
β¨ Topic: Web Scraping using Python (BeautifulSoup)
βββββββββββββββββββ
π What is Web Scraping?
Web scraping means extracting data from websites automatically using code.
Used for:
β Data collection
β Price tracking
β News aggregation
β Market research
βββββββββββββββββββ
π¦ Required Libraries
Install libraries:
pip install requests
pip install beautifulsoup4
Import in Python:
import requests
from bs4 import BeautifulSoup
βββββββββββββββββββ
π Step 1: Get Website HTML
import requests
url = "https://example.comβ οΏ½"
response = requests.get(url)
html = response.text
print(html)
This fetches the HTML source of the webpage.
βββββββββββββββββββ
π Step 2: Parse HTML using BeautifulSoup
from bs4 import BeautifulSoup
soup = BeautifulSoup(html, "html.parser")
print(soup.title)
Extracts the title of the webpage.
βββββββββββββββββββ
πΉ Extract Specific Data
Example: Get all headings
for heading in soup.find_all("h1"):
print(heading.text)
βββββββββββββββββββ
πΉ Extract Links from Page
for link in soup.find_all("a"):
print(link.get("href"))
βββββββββββββββββββ
πΉ Extract Paragraph Text
for p in soup.find_all("p"):
print(p.text)
βββββββββββββββββββ
β Important Note
Always check a websiteβs robots.txt before scraping.
Some websites do not allow scraping.
βββββββββββββββββββ
π§ Real-world Uses of Web Scraping
β Job listing collectors
β Product price trackers
β News aggregators
β Social media analysis
βββββββββββββββββββ
π Practice Tasks β Day 45
β Fetch website HTML
β Extract title
β Extract all links
β Extract paragraph text
βββββββββββββββββββ
π― Day 45 Goal
β Understand web scraping concept
β Use BeautifulSoup
β Extract structured data
βββββββββββββββββββ
π
π₯ Automating Tasks with Python (Automation Scripts)
β¨ Stay Connected | Keep Coding
π TechByWebCoder
β¨ Topic: Web Scraping using Python (BeautifulSoup)
βββββββββββββββββββ
π What is Web Scraping?
Web scraping means extracting data from websites automatically using code.
Used for:
β Data collection
β Price tracking
β News aggregation
β Market research
βββββββββββββββββββ
π¦ Required Libraries
Install libraries:
pip install requests
pip install beautifulsoup4
Import in Python:
import requests
from bs4 import BeautifulSoup
βββββββββββββββββββ
π Step 1: Get Website HTML
import requests
url = "https://example.comβ οΏ½"
response = requests.get(url)
html = response.text
print(html)
This fetches the HTML source of the webpage.
βββββββββββββββββββ
π Step 2: Parse HTML using BeautifulSoup
from bs4 import BeautifulSoup
soup = BeautifulSoup(html, "html.parser")
print(soup.title)
Extracts the title of the webpage.
βββββββββββββββββββ
πΉ Extract Specific Data
Example: Get all headings
for heading in soup.find_all("h1"):
print(heading.text)
βββββββββββββββββββ
πΉ Extract Links from Page
for link in soup.find_all("a"):
print(link.get("href"))
βββββββββββββββββββ
πΉ Extract Paragraph Text
for p in soup.find_all("p"):
print(p.text)
βββββββββββββββββββ
β Important Note
Always check a websiteβs robots.txt before scraping.
Some websites do not allow scraping.
βββββββββββββββββββ
π§ Real-world Uses of Web Scraping
β Job listing collectors
β Product price trackers
β News aggregators
β Social media analysis
βββββββββββββββββββ
π Practice Tasks β Day 45
β Fetch website HTML
β Extract title
β Extract all links
β Extract paragraph text
βββββββββββββββββββ
π― Day 45 Goal
β Understand web scraping concept
β Use BeautifulSoup
β Extract structured data
βββββββββββββββββββ
π
Next Topic β Day 46π₯ Automating Tasks with Python (Automation Scripts)
β¨ Stay Connected | Keep Coding
π TechByWebCoder
PYTHON β DAY 46 STUDY MATERIAL
β¨ Topic: Automating Tasks with Python
βββββββββββββββββββ
π What is Automation?
Automation means using code to perform repetitive tasks automatically.
Instead of doing work manually, Python can do it faster and automatically.
Examples:
β Renaming multiple files
β Sending emails automatically
β Data backup scripts
β Auto downloading files
βββββββββββββββββββ
π¦ Useful Python Modules for Automation
β os β File operations
β shutil β File moving/copying
β schedule β Task scheduling
β smtplib β Email automation
β pyautogui β Keyboard & mouse automation
βββββββββββββββββββ
π Example 1: List Files in Folder
import os
files = os.listdir()
for file in files:
print(file)
Shows all files in the current directory.
βββββββββββββββββββ
β Example 2: Rename Multiple Files
import os
files = os.listdir()
for i, file in enumerate(files):
os.rename(file, f"file_{i}.txt")
This renames files automatically π₯
βββββββββββββββββββ
π Example 3: Copy Files Automatically
import shutil
shutil.copy("source.txt", "backup.txt")
Used for file backup automation.
βββββββββββββββββββ
β° Example 4: Schedule Tasks
Install schedule library:
pip install schedule
Example:
import schedule
import time
def job():
print("Task executed")
schedule.every(5).seconds.do(job)
while True:
schedule.run_pending()
time.sleep(1)
Runs task every 5 seconds.
βββββββββββββββββββ
π§ Real-world Automation Examples
β Auto email sender
β Auto report generator
β File organizer
β Social media automation
βββββββββββββββββββ
π Practice Tasks β Day 46
β List files in directory
β Rename files automatically
β Copy file backup
β Schedule a task
βββββββββββββββββββ
π― Day 46 Goal
β Understand automation concept
β Use OS & file modules
β Create simple automation scripts
βββββββββββββββββββ
π Next Topic β Day 47
π₯ Sending Emails using Python
β¨ Stay Connected | Keep Coding
π TechByWebCoder
β¨ Topic: Automating Tasks with Python
βββββββββββββββββββ
π What is Automation?
Automation means using code to perform repetitive tasks automatically.
Instead of doing work manually, Python can do it faster and automatically.
Examples:
β Renaming multiple files
β Sending emails automatically
β Data backup scripts
β Auto downloading files
βββββββββββββββββββ
π¦ Useful Python Modules for Automation
β os β File operations
β shutil β File moving/copying
β schedule β Task scheduling
β smtplib β Email automation
β pyautogui β Keyboard & mouse automation
βββββββββββββββββββ
π Example 1: List Files in Folder
import os
files = os.listdir()
for file in files:
print(file)
Shows all files in the current directory.
βββββββββββββββββββ
β Example 2: Rename Multiple Files
import os
files = os.listdir()
for i, file in enumerate(files):
os.rename(file, f"file_{i}.txt")
This renames files automatically π₯
βββββββββββββββββββ
π Example 3: Copy Files Automatically
import shutil
shutil.copy("source.txt", "backup.txt")
Used for file backup automation.
βββββββββββββββββββ
β° Example 4: Schedule Tasks
Install schedule library:
pip install schedule
Example:
import schedule
import time
def job():
print("Task executed")
schedule.every(5).seconds.do(job)
while True:
schedule.run_pending()
time.sleep(1)
Runs task every 5 seconds.
βββββββββββββββββββ
π§ Real-world Automation Examples
β Auto email sender
β Auto report generator
β File organizer
β Social media automation
βββββββββββββββββββ
π Practice Tasks β Day 46
β List files in directory
β Rename files automatically
β Copy file backup
β Schedule a task
βββββββββββββββββββ
π― Day 46 Goal
β Understand automation concept
β Use OS & file modules
β Create simple automation scripts
βββββββββββββββββββ
π Next Topic β Day 47
π₯ Sending Emails using Python
β¨ Stay Connected | Keep Coding
π TechByWebCoder