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 6 STUDY MATERIAL
โœจ Topic: while Loop in Python

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

๐Ÿ“Œ What is a Loop?
A loop is used to repeat a block of code multiple times until a condition becomes False.

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

๐Ÿ” What is while Loop?

The while loop executes a block of code as long as the condition is True.

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

๐Ÿ”น Syntax of while Loop

while condition:
statement
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Example: Print Numbers 1 to 5

i = 1
while i <= 5:
print(i)
i = i + 1
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”น Example: Sum of Numbers

i = 1
sum = 0
while i <= 5:
sum = sum + i
i = i + 1
print(sum)

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

๐Ÿ”น Infinite Loop
A loop that never ends is called an infinite loop.

Example (Avoid this):
while True:
print("Python")

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

๐Ÿ”น Common Mistakes in while Loop

โŒ Forgetting to update loop variable
โŒ Wrong condition
โŒ Infinite loop

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

๐Ÿ“ Practice Tasks โ€“ Day 6

โœ” Print numbers from 1 to 10
โœ” Print even numbers using while loop
โœ” Find factorial of a number
โœ” Reverse a number

Example Program:
num = int(input("Enter a number: "))
rev = 0
while num > 0:
digit = num % 10
rev = rev * 10 + digit
num = num // 10
print("Reverse:", rev)

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

๐ŸŽฏ Day 6 Goal

โœ” Understand repetition using while loop
โœ” Avoid infinite loops

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

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

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

๐Ÿ“Œ What is for Loop?
The for loop is used to iterate over a sequence such as a list, tuple, string, or range.

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

๐Ÿ”น Syntax of for Loop
for variable in sequence:
statement

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

๐Ÿ”น Using range() Function

range() generates a sequence of numbers.
range(start, stop, step)

Example:
for i in range(1, 6):
print(i)

Output:
1 2 3 4 5

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

๐Ÿ”น Example: Print Even Numbers

for i in range(2, 11, 2):
print(i)

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

๐Ÿ”น Looping Through a String
for ch in "Python":
print(ch)

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”
๐Ÿ”น Nested for Loop
A for loop inside another for loop.

Example:
for i in range(1, 4):
for j in range(1, 4):
print(i, j)

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

๐Ÿ”น Difference Between for and while Loop

โ€ข for loop is used when number of iterations is known
โ€ข while loop is used when condition is unknown

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

๐Ÿ“ Practice Tasks โ€“ Day 7

โœ” Print numbers from 1 to 10
โœ” Print multiplication table
โœ” Print characters of a string
โœ” Create star pattern using nested loop

Example Program:
for i in range(1, 6):
print("*" * i)

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

๐ŸŽฏ Day 7 Goal
โœ” Master iteration using for loop
โœ” Use range() confidently

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

๐Ÿ“… Next Topic โ€“ Day 8
๐Ÿ”ฅ break, continue & pass Statements
โœจ Stay Connected | Keep Coding
๐Ÿš€ TechByWebCoder
๐Ÿ PYTHON โ€“ DAY 8 STUDY MATERIAL
โœจ Topic: break, continue & pass Statements
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“Œ Control Statements in Python

Control statements are used to change the normal flow of loops.
Python provides three control statements:

โ€ข break
โ€ข continue
โ€ข pass

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

๐Ÿ›‘ break Statement

The break statement is used to terminate the loop immediately when a condition is met.

Example:
for i in range(1, 10):
if i == 5:
break
print(i)
Output:
1 2 3 4

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

โญ continue Statement

The continue statement skips the current iteration and moves to the next one.

Example:
for i in range(1, 6):
if i == 3:
continue
print(i)
Output:
1 2 4 5

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

โธ pass Statement

The pass statement is used as a placeholder where a statement is required but no action is needed.

Example:
for i in range(1, 5):
if i == 2:
pass
print(i)

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

๐Ÿ” Difference Between break, continue & pass

โ€ข break โ†’ Stops loop completely
โ€ข continue โ†’ Skips current iteration
โ€ข pass โ†’ Does nothing, avoids error

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

๐Ÿ“ Practice Tasks โ€“ Day 8

โœ” Stop loop when number equals 7
โœ” Skip printing number 5
โœ” Use pass inside empty if block
โœ” Combine loop with break & continue

Example Program:
for i in range(1, 11):
if i == 5:
continue
if i == 8:
break
print(i)

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

๐ŸŽฏ Day 8 Goal
โœ” Control loop execution
โœ” Understand loop flow clearly

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

๐Ÿ“… Next Topic โ€“ Day 9
๐Ÿ”ฅ Pattern Programs (Stars & Numbers)
โœจ Stay Connected | Keep Coding
๐Ÿš€ TechByWebCoder


React โค๏ธ If You Got It Right
๐Ÿ PYTHON โ€“ DAY 9 STUDY MATERIAL
โœจ Topic: Pattern Programs (Stars & Numbers)

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

๐Ÿ“Œ What are Pattern Programs?

Pattern programs use loops and logic to print designs using stars (*) or numbers.
They help improve loop control and logical thinking.

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

โญ Star Pattern โ€“ Right Triangle

Code:
for i in range(1, 6):
print("*" * i)

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

โญ Star Pattern โ€“ Inverted Triangle

Code:
for i in range(5, 0, -1):
print("*" * i)

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

โญ Pyramid Star Pattern

Code:
n = 4
for i in range(n):
print(" " * (n - i - 1) + "*" * (2 * i + 1))

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

๐Ÿ”ข Number Pattern โ€“ Increasing Numbers

1
12
123
1234

Code:
for i in range(1, 5):
for j in range(1, i + 1):
print(j, end="")
print()
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ”ข Number Pattern โ€“ Same Number

1
22
333
4444

Code:
for i in range(1, 5):
print(str(i) * i)

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

๐Ÿ’ก Logic Tips for Pattern Programs

โœ” Outer loop โ†’ rows
โœ” Inner loop โ†’ columns
โœ” Spaces control alignment
โœ” Practice regularly

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

๐Ÿ“ Practice Tasks โ€“ Day 9

โœ” Print hollow star rectangle
โœ” Print number pyramid
โœ” Print reverse number pattern
โœ” Create your own pattern

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

๐ŸŽฏ Day 9 Goal
โœ” Master nested loops
โœ” Improve logical thinking

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

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

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

๐Ÿ“Œ What is a Function?

A function is a block of reusable code that performs a specific task.
Functions help reduce code repetition and improve readability.

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

๐Ÿ”น Why Use Functions?

โœ” Code reusability
โœ” Better organization
โœ” Easy debugging
โœ” Saves time and effort

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

๐Ÿงฉ Syntax of a Function

def function_name():
statement

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

๐Ÿ”น Example: Simple Function

def greet():
print("Hello Python")
greet()
Output:
Hello Python

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

๐Ÿ”น Function with Parameters
Parameters are values passed to a function.

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

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

๐Ÿ”น Function with Return Value

The return statement sends a value back to the caller.

Example:
def add(a, b):
return a + b
result = add(10, 20)
print(result)

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

๐Ÿ”น Function Call

Calling a function means executing it.
Example:
add(5, 3)

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

โš ๏ธ Important Points

โ€ข Function name should be meaningful
โ€ข Use indentation properly
โ€ข return ends the function execution

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

๐Ÿ“ Practice Tasks โ€“ Day 10

โœ” Create a function to print your name
โœ” Create a function to add two numbers
โœ” Create a function to find square of a number
โœ” Create a function to check even or odd

Example Program:
def square(n):
return n * n
print(square(5))

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

๐ŸŽฏ Day 10 Goal
โœ” Understand function basics
โœ” Write reusable code

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

๐Ÿ“… Next Topic โ€“ Day 11
๐Ÿ”ฅ Function Arguments (Types)
โœจ Stay Connected | Keep Coding
๐Ÿš€ TechByWebCoder
โค1
๐Ÿ 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