๐ 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
โจ 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
โจ 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
โจ 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