Python Programming - Detailed Notes
Module 0: Prerequisite
Introduction to Programming: Understanding algorithms, flowcharts, and pseudocode.
Example Algorithm:
1. Start
2. Take two numbers as input
3. Add the numbers
4. Display the sum
5. Stop
Module 1: Introduction to Python
Python is a high-level, interpreted programming language.
Data Types: int, float, str, list, tuple, set, dict
Example:
name = input("Enter your name: ")
print("Hello, " + name + "!")
Module 2: Control Flow and Functions
Control Statements: if, else, elif
Loops: for, while
Example Function:
def check_number(n):
if n % 2 == 0:
return "Even"
else:
return "Odd"
print(check_number(5))
Module 3: File Handling, Packaging, and Debugging
File Handling:
with open("sample.txt", "w") as file:
file.write("Hello, Python!")
Module 4: Object-Oriented Programming (OOP)
Concepts: Class, Object, Encapsulation, Inheritance, Polymorphism
Example:
class Animal:
def __init__(self, name):
self.name = name
def speak(self):
return "I am an animal"
class Dog(Animal):
def speak(self):
return "Bark!"
dog = Dog("Tommy")
print(dog.speak()) # Output: Bark!
Module 5: Advanced Python Concepts
Regular Expressions:
import re
pattern = r"\b\d{3}-\d{3}-\d{4}\b"
text = "Call me at 123-456-7890."
match = re.findall(pattern, text)
print(match) # Output: ['123-456-7890']
Module 6: Python Libraries
NumPy, Pandas, Matplotlib
Example:
import numpy as np
arr = np.array([1, 2, 3, 4, 5])
print(arr.mean()) # Output: 3.0