Day7 Notes
Day7 Notes
Topics Covered
• Functions in Python
• Python File Handling (Files I/O)
• NumPy Overview
• Pandas Overview
Basic Syntax:
Calling Functions:
def greet(name):
return f"Hello, {name}!"
print(greet("Ashish"))
Keyword Arguments:
student(age=20, name="Rahul")
Default Parameters:
def greet(name="Guest"):
print("Hello", name)
def show_details(**kwargs):
for key, value in kwargs.items():
print(f"{key}: {value}")
Return Statement:
square = lambda x: x * x
print(square(4))
nums = [1, 2, 3, 4, 5]
even = list(filter(lambda x: x % 2 == 0, nums))
2. Modules in Python
Modules organize related code (functions, classes) into separate files.
Opening Files:
File Modes:
• r - Read
• w - Write (overwrite)
• a - Append
• rb/wb/ab - Binary Read/Write/Append
• r+/w+/a+ - Read+Write variants
Writing to a File:
f = open("file.txt", "w")
f.write("Hello World")
f.close()
f = open("file.txt", "r")
print(f.read())
Reading line-by-line:
f = open("file.txt", "r")
print(f.readline())
4. NumPy Overview
NumPy is used for numerical computations with support for multi-
dimensional arrays.
Installation:
Importing NumPy:
import numpy as np
5. Pandas Overview
Pandas is a powerful data analysis library in Python.
Installation:
Importing Pandas:
import pandas as pd