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

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

For promotions & collaborations:
techbywedcoder@gmail.com

Join now and accelerate your Python journey!
Download Telegram
๐Ÿ PYTHON โ€“ DAY 11 STUDY MATERIAL
โœจ Topic: Function Arguments (Types)

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

๐Ÿ“Œ What are Function Arguments?

Arguments are values passed to a function when it is called.
They allow functions to work with different inputs.

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

๐Ÿ”น 1. Positional Arguments

Arguments are passed in the same order as parameters.

Example:
def add(a, b):
print(a + b)
add(10, 5)

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

๐Ÿ”น 2. Keyword Arguments

Arguments are passed using parameter names, order does not matter.

Example:
def greet(name, msg):
print(msg, name)
greet(msg="Hello", name="Soham")

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

๐Ÿ”น 3. Default Arguments

Default values are used when no argument is passed.

Example:
def greet(name="User"):
print("Hello", name)
greet()
greet("Python")
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”
๐Ÿ”น 4. Variable-Length Arguments (*args)

Used when number of arguments is unknown.

Example:
def total(*nums):
print(sum(nums))
total(10, 20, 30)

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

๐Ÿ”น 5. Keyword Variable-Length Arguments

Used to pass key-value pairs.

Example:
def details(**info):
print(info)
details(name="Soham", age=20)

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

โš ๏ธ Important Notes

โ€ข Positional arguments come first
โ€ข Default arguments should be last
โ€ข *args โ†’ tuple
โ€ข **kwargs โ†’ dictionary

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

๐Ÿ“ Practice Tasks โ€“ Day 11

โœ” Use positional & keyword arguments
โœ” Create function with default value
โœ” Create function using *args
โœ” Create function using **kwargs

Example Program:
def marks(*m):
print(sum(m))
marks(60, 70, 80)

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

๐ŸŽฏ Day 11 Goal
โœ” Understand all types of function arguments
โœ” Write flexible functions

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

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

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

๐Ÿ“Œ What is Recursion?

Recursion is a technique where a function calls itself to solve a problem.
It is useful for problems that can be broken into smaller sub-problems.

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

๐Ÿ”น Two Important Parts of Recursion

1๏ธโƒฃ Base Condition โ€“ Stops recursion
2๏ธโƒฃ Recursive Call โ€“ Function calls itself
Without base condition โ†’ infinite recursion โŒ

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

๐Ÿ”น Syntax of Recursive Function

def function_name():
if base_condition:
return value
return function_name(smaller_problem)

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

๐Ÿ”ข Example: Factorial using Recursion

def factorial(n):
if n == 1:
return 1
return n * factorial(n - 1)
print(factorial(5))

Output:
120

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

๐Ÿ” Example: Fibonacci Series

def fib(n):
if n <= 1:
return n
return fib(n - 1) + fib(n - 2)
print(fib(6))

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

โš ๏ธ Important Notes

โ€ข Always define a base case
โ€ข Recursive calls increase memory usage
โ€ข Not suitable for very large problems

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

๐Ÿ“ Practice Tasks โ€“ Day 12

โœ” Find factorial of a number
โœ” Print Fibonacci series
โœ” Calculate sum of digits using recursion
โœ” Reverse a number using recursion

Example Program:
def sum_digits(n):
if n == 0:
return 0
return n % 10 + sum_digits(n // 10)
print(sum_digits(123))

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

๐ŸŽฏ Day 12 Goal
โœ” Understand recursive thinking
โœ” Write correct recursive functions

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

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

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

๐Ÿ“Œ What is a String?

A string is a sequence of characters enclosed in single (' ') or double (" ") quotes.

Example:
name = "Python"
msg = 'Hello'

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

๐Ÿ”ข String Indexing

Each character in a string has an index number, starting from 0.

Example:
text = "Python"
text[0] โ†’ P
text[1] โ†’ y
text[-1] โ†’ n

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

โœ‚๏ธ String Slicing
Used to extract a portion of a string.

Syntax:
string[start:end]

Example:
text = "Python"
print(text[0:3]) # Pyt
print(text[2:]) # thon
print(text[:4]) # Pyth

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

๐Ÿ” String Looping

Example:
for ch in "Python":
print(ch)

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

๐Ÿงฎ String Length
Use len() to find string length.

Example:
text = "Python"
print(len(text))

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

๐Ÿ”’ Strings are Immutable

Strings cannot be changed once created.

Example:
text = "Python"
text[0] = 'J' โŒ Error

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

๐Ÿ“ Practice Tasks โ€“ Day 13

โœ” Print each character of a string
โœ” Reverse a string
โœ” Find length of a string
โœ” Extract substring

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

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

๐ŸŽฏ Day 13 Goal
โœ” Understand string basics
โœ” Use indexing and slicing confidently

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

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

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

๐Ÿ“Œ What are String Methods?

String methods are built-in functions used to manipulate and format strings.

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

๐Ÿ”ค Common String Methods

๐Ÿ”น upper() โ€“ Converts string to uppercase

Example:
text = "python"
print(text.upper())

๐Ÿ”น lower() โ€“ Converts string to lowercase
print(text.lower())

๐Ÿ”น title() โ€“ Capitalizes first letter of each word
print("hello world".title())

๐Ÿ”น capitalize() โ€“ Capitalizes first character
print("python".capitalize())

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

โœ‚๏ธ Trim Methods

๐Ÿ”น strip() โ€“ Removes spaces from both sides
๐Ÿ”น lstrip() โ€“ Removes left spaces
๐Ÿ”น rstrip() โ€“ Removes right spaces

Example:
text = " python "
print(text.strip())

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

๐Ÿ” Replace & Split

๐Ÿ”น replace() โ€“ Replaces part of string
print("hello python".replace("python", "world"))

๐Ÿ”น split() โ€“ Splits string into list
print("a,b,c".split(","))

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

๐Ÿ” Search Methods

๐Ÿ”น find() โ€“ Returns index of substring
print("python".find("t"))

๐Ÿ”น count() โ€“ Counts occurrences
print("banana".count("a"))

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

โ“ Check Methods

๐Ÿ”น isalpha() โ€“ Checks alphabets
๐Ÿ”น isdigit() โ€“ Checks digits
๐Ÿ”น isalnum() โ€“ Checks alphanumeric

Example:
print("Python123".isalnum())

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

๐Ÿ“ Practice Tasks โ€“ Day 14
โœ” Convert string to uppercase
โœ” Count vowels in string
โœ” Replace a word in sentence
โœ” Split full name into first and last name

Example Program:
text = input("Enter text: ")
print(text.upper())

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

๐ŸŽฏ Day 14 Goal
โœ” Master common string methods
โœ” Manipulate strings effectively

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

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

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

๐Ÿ“Œ What is a List?

A list is a collection of items stored in a single variable.
Lists are ordered, mutable (changeable) and allow duplicate values.

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

๐Ÿ”น Creating a List

Example:
nums = [10, 20, 30, 40]
names = ["Python", "Java", "C"]

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

๐Ÿ”ข List Indexing

Example:
nums = [10, 20, 30]
nums[0] โ†’ 10
nums[-1] โ†’ 30

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

โœ‚๏ธ List Slicing

Example:
nums = [1, 2, 3, 4, 5]
print(nums[1:4]) # [2, 3, 4]

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

โœ๏ธ Modify List Elements

Example:
nums = [10, 20, 30]
nums[1] = 25
print(nums)

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

๐Ÿ” Looping Through List

Example:
for n in nums:
print(n)

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

๐Ÿงฎ List Length

Example:
print(len(nums))

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

๐Ÿ“ Practice Tasks โ€“ Day 15

โœ” Create a list of numbers
โœ” Access elements using index
โœ” Change list elements
โœ” Print all list elements using loop

Example Program:
nums = [5, 10, 15, 20]
for n in nums:
print(n)

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

๐ŸŽฏ Day 15 Goal
โœ” Understand list basics
โœ” Use lists confidently

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

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

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

๐Ÿ“Œ What are List Methods?

List methods are built-in functions used to add, remove, and manage list elements.

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

โž• Adding Elements

๐Ÿ”น append() โ€“ Adds element at the end
Example:
nums = [1, 2, 3]
nums.append(4)

๐Ÿ”น insert() โ€“ Adds element at specific index
nums.insert(1, 10)

๐Ÿ”น extend() โ€“ Adds multiple elements
nums.extend([5, 6])

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

โž– Removing Elements

๐Ÿ”น remove() โ€“ Removes specific value
nums.remove(10)

๐Ÿ”น pop() โ€“ Removes element by index
nums.pop()
nums.pop(1)

๐Ÿ”น clear() โ€“ Removes all elements
nums.clear()
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”„ Other Useful List Methods

๐Ÿ”น sort() โ€“ Sorts list
nums.sort()

๐Ÿ”น reverse() โ€“ Reverses list
nums.reverse()

๐Ÿ”น count() โ€“ Counts occurrence
nums.count(2)

๐Ÿ”น index() โ€“ Returns index of value
nums.index(3)

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

๐Ÿง  List Copy

๐Ÿ”น copy() โ€“ Creates shallow copy
new_list = nums.copy()

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

โš ๏ธ Important Notes

โ€ข Lists are mutable
โ€ข sort() changes original list
โ€ข Use sorted() to keep original list

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

๐Ÿ“ Practice Tasks โ€“ Day 16

โœ” Add elements using append & insert
โœ” Remove elements using pop & remove
โœ” Sort a list
โœ” Reverse a list

Example Program:
nums = [4, 2, 1, 3]
nums.sort()
print(nums)

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

๐ŸŽฏ Day 16 Goal
โœ” Master list operations
โœ” Manage list data efficiently

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

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

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

๐Ÿ“Œ What is a Tuple?

A tuple is a collection of items stored in a single variable.
Tuples are ordered and immutable (cannot be changed).

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

๐Ÿ”น Creating a Tuple

Example:
t = (10, 20, 30)
names = ("Python", "Java", "C")
Single element tuple:
x = (10,) โœ” comma is required

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

๐Ÿ”ข Tuple Indexing

Example:
t = (10, 20, 30)
t[0] โ†’ 10
t[-1] โ†’ 30

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

โœ‚๏ธ Tuple Slicing

Example:
t = (1, 2, 3, 4, 5)
print(t[1:4])

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

๐Ÿ” Looping Through Tuple

Example:
for item in t:
print(item)

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

๐Ÿ”’ Tuple Immutability
Tuple elements cannot be modified.

Example:
t = (10, 20, 30)
t[0] = 5 โŒ Error

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

๐Ÿงฎ Tuple Methods

๐Ÿ”น count() โ€“ Counts occurrence
๐Ÿ”น index() โ€“ Returns index

Example:
t = (1, 2, 2, 3)
print(t.count(2))
print(t.index(3))

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

๐Ÿ”„ Convert Tuple to List

Example:
t = (1, 2, 3)
lst = list(t)

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

๐Ÿ“ Practice Tasks โ€“ Day 17

โœ” Create tuple of numbers
โœ” Access elements using index
โœ” Loop through tuple
โœ” Convert tuple to list

Example Program:
t = (5, 10, 15)
for i in t:
print(i)

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

๐ŸŽฏ Day 17 Goal
โœ” Understand tuple basics
โœ” Know difference between list & tuple

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

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

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

๐Ÿ“Œ What is a Set?

A set is a collection of unique elements stored in a single variable.
Sets are unordered and do not allow duplicate values.

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

๐Ÿ”น Creating a Set

Example:
s = {10, 20, 30}
names = {"Python", "Java", "C"}
Duplicate values are removed automatically:
s = {1, 2, 2, 3}
Output โ†’ {1, 2, 3}

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

โž• Add Elements to Set

๐Ÿ”น add() โ€“ Adds single element
s.add(40)

๐Ÿ”น update() โ€“ Adds multiple elements
s.update([50, 60])
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

โž– Remove Elements from Set

๐Ÿ”น remove() โ€“ Removes element (error if not found)
s.remove(20)

๐Ÿ”น discard() โ€“ Removes element (no error)
s.discard(100)

๐Ÿ”น pop() โ€“ Removes random element
s.pop()

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

๐Ÿ”„ Set Operations

๐Ÿ”น union() โ€“ Combines sets
๐Ÿ”น intersection() โ€“ Common elements
๐Ÿ”น difference() โ€“ Remaining elements

Example:
a = {1, 2, 3}
b = {3, 4, 5}
print(a.union(b))
print(a.intersection(b))
print(a.difference(b))

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

๐Ÿงฎ Check Membership

Example:
print(2 in a)

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

๐Ÿ“ Practice Tasks โ€“ Day 18

โœ” Create a set
โœ” Add and remove elements
โœ” Perform union & intersection
โœ” Remove duplicate values from list using set

Example Program:
lst = [1, 2, 2, 3, 4]
s = set(lst)
print(s)

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

๐ŸŽฏ Day 18 Goal
โœ” Understand set properties
โœ” Perform set operations

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

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

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

๐Ÿ“Œ What is a Dictionary?

A dictionary stores data in keyโ€“value pairs.
Dictionaries are unordered, mutable, and keys must be unique.

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

๐Ÿ”น Creating a Dictionary

Example:
student = {
"name": "Soham",
"age": 20,
"course": "Python"
}

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

๐Ÿ”‘ Access Dictionary Values

Example:
print(student["name"])
print(student.get("age"))

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

โœ๏ธ Modify Dictionary

Example:
student["age"] = 21
student["city"] = "Pune"

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

โŒ Remove Dictionary Items

๐Ÿ”น pop() โ€“ Removes specific key
student.pop("city")

๐Ÿ”น popitem() โ€“ Removes last item
student.popitem()

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

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

๐Ÿ” Loop Through Dictionary

Example:
for key in student:
print(key, student[key])

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

๐Ÿงฎ Dictionary Methods

๐Ÿ”น keys() โ€“ Returns all keys
๐Ÿ”น values() โ€“ Returns all values
๐Ÿ”น items() โ€“ Returns key-value pairs

Example:
print(student.keys())
print(student.values())

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

๐Ÿ“ Practice Tasks โ€“ Day 19

โœ” Create student dictionary
โœ” Add and update values
โœ” Loop through dictionary
โœ” Delete a key

Example Program:
student = {"name": "Amit", "age": 22}
for k, v in student.items():
print(k, v)

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

๐ŸŽฏ Day 19 Goal
โœ” Understand key-value storage
โœ” Use dictionaries effectively

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

๐Ÿ“… Next Topic โ€“ Day 20
๐Ÿ”ฅ Dictionary Methods & Nested Dictionary
โœจ Stay Connected | Keep Coding
๐Ÿš€ TechByWebCoder
๐Ÿ PYTHON โ€“ DAY 20 STUDY MATERIAL
โœจ Topic: Dictionary Methods & Nested Dictionary

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

๐Ÿ“Œ Important Dictionary Methods

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

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

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

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

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

โŒ Removing Dictionary Data

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

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

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

๐Ÿงฉ Nested Dictionary

A dictionary inside another dictionary is called a nested dictionary.

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

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

๐Ÿ” Loop Through Nested Dictionary

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

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

๐Ÿงฎ Copy Dictionary

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

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

๐Ÿ“ Practice Tasks โ€“ Day 20

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

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

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

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

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

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

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

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

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

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

๐Ÿง  Quick Revision Points

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

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

๐Ÿงช Practice Programs โ€“ Day 21

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

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

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

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

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

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

3๏ธโƒฃ Reverse a string

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

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

4๏ธโƒฃ Count frequency using dictionary

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

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

โญ Challenge Tasks

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

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

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

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

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

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

๐Ÿ“Œ What is File Handling?

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

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

๐Ÿ“‚ Types of Files

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

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

๐Ÿ“ Opening a File

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

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

๐Ÿ“– Reading from a File

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

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

โœ๏ธ Writing to a File

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

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

โž• Append Data to File

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

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

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

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

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

๐Ÿ“ Practice Tasks โ€“ Day 22

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

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

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

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

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

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

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

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

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

๐Ÿ“Œ File Modes in Python

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

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

๐Ÿ“– Important File Methods

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

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

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

โœ๏ธ Writing Multiple Lines

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

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

๐Ÿ“ File Cursor Position

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

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

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

๐Ÿงน Closing a File

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

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

โš ๏ธ Common File Errors

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

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

๐Ÿ“ Practice Tasks โ€“ Day 23

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

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

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

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

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

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

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

๐Ÿ“Œ What is an Exception?

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

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

๐Ÿ›ก Why Use Exception Handling?

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

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

๐Ÿ”น try-except Block

Syntax:
try:
risky_code
except:
error_handling_code

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

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

๐Ÿ”น Handling Specific Exceptions

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

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

๐Ÿ”น Multiple except Blocks

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

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

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

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

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

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

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

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

๐Ÿ“ Practice Tasks โ€“ Day 24

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

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

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

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

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

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

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

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

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

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

๐Ÿงฉ Why Use Custom Exceptions?

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

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

๐Ÿ”น Creating a Custom Exception

Custom exceptions are created by inheriting from Exception class.

Example:
class AgeError(Exception):
pass

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

๐Ÿ”น Raising a Custom Exception

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

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

๐Ÿ”น Handling Custom Exception

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

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

๐Ÿ”น Using raise Keyword

The raise keyword is used to trigger an exception manually.

Example:
raise ValueError("Invalid value")

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

โš ๏ธ Important Notes

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

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

๐Ÿ“ Practice Tasks โ€“ Day 25

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

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

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

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

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

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

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

๐Ÿ“Œ What is a Module?

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

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

๐Ÿ“ฆ Importing a Module

Syntax:
import module_name

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

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

๐Ÿ”น Import Specific Function

Syntax:
from module_name import function_name

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

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

๐Ÿ”น Import with Alias

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

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

๐Ÿงฎ Common Built-in Modules

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

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

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

๐Ÿ›  Creating User-Defined Module

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

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

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

โš ๏ธ Important Points

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

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

๐Ÿ“ Practice Tasks โ€“ Day 26

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

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

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

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

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

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

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

๐Ÿ“Œ What is OOP?

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

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

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

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

Syntax:
class ClassName:
pass

Example:
class Student:
pass

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

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

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

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

๐Ÿ”น Class with Attributes

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

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

๐Ÿ”น init Constructor Method

Used to initialize object data.

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

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

๐Ÿ”น Instance Method

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

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

๐Ÿง  Understanding self Keyword

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

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

๐Ÿ“ Practice Tasks โ€“ Day 27

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

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

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

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

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

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

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

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

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

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

๐Ÿ”’ Access Modifiers in Python

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

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

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

๐Ÿ”น Public Variable Example

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

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

๐Ÿ”น Protected Variable Example

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

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

๐Ÿ” Private Variable Example

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

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

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

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

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

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

๐Ÿ“ Practice Tasks โ€“ Day 28

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

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

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

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

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

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

๐Ÿ“Œ What is Inheritance?

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

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

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

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

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

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

๐Ÿ”น Basic Inheritance Example

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

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

๐Ÿ”น Inheritance with Constructor

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

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

๐Ÿ”น Using super() Function

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

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

๐Ÿ”น Types of Inheritance in Python

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

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

๐Ÿง  Multilevel Inheritance Example

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

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

๐Ÿ“ Practice Tasks โ€“ Day 29

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

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

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

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

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

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

๐Ÿ“Œ What is Polymorphism?

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

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

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

๐Ÿ”น Method Overriding (Runtime Polymorphism)

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

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

Output:
Dog barks

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

๐Ÿ”น Polymorphism with Multiple Classes

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

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

๐Ÿ”น Operator Overloading

Python allows operators to behave differently for different data types.

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

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

๐Ÿ”น Method Overloading in Python?

Python does NOT support traditional method overloading like Java.

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

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

๐Ÿง  Real Life Example

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

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

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

๐Ÿ“ Practice Tasks โ€“ Day 30

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

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

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

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

๐Ÿ“… Next Topic โ€“ Day 31
๐Ÿ”ฅ OOP โ€“ Abstraction
โœจ Stay Connected | Keep Coding
๐Ÿš€ TechByWebCoder