Python – Complete Notes with Examples
These notes provide a comprehensive understanding of Python programming. Python is widely used in data
analysis, machine learning, automation, and web development. The notes cover core programming concepts,
data structures, functions, libraries, and examples useful for beginners and aspiring Data Analysts.
1. Introduction to Python
Python is a high-level, interpreted programming language known for its simplicity and readability.
It is widely used in fields such as: • Data Analysis • Artificial Intelligence • Machine Learning • Web Development •
Automation
Example Python Program:
print("Hello World")
Output: Hello World
2. Variables and Data Types
Variables are used to store data.
Example:
name = "John" age = 25 salary = 50000.5
Common Data Types:
Integer (int) Example: 10
Float Example: 10.5
String Example: "Python"
Boolean Example: True / False
3. Operators in Python
Operators perform operations on variables.
Arithmetic Operators: + Addition - Subtraction * Multiplication / Division % Modulus
Example:
a = 10 b = 5
print(a + b)
Output: 15
4. Conditional Statements
Conditional statements allow decision making.
If Statement Example:
age = 18
if age >= 18: print("Eligible to vote")
Else Example:
marks = 40
if marks >= 50: print("Pass") else: print("Fail")
5. Loops in Python
Loops execute a block of code repeatedly.
For Loop Example:
for i in range(5): print(i)
Output: 0 1 2 3 4
While Loop Example:
count = 1 while count <= 5: print(count) count += 1
6. Python Data Structures
Lists Ordered and mutable collection.
Example: numbers = [1,2,3,4]
Tuple Ordered but immutable.
Example: data = (10,20,30)
Dictionary Stores data as key-value pairs.
Example: student = {"name":"John","marks":90}
Set Unordered collection of unique values.
7. Functions in Python
Functions are reusable blocks of code.
Example:
def add(a,b): return a + b
result = add(5,3) print(result)
Output: 8
Functions help make code modular and reusable.
8. Python Libraries for Data Analysis
Python provides powerful libraries for data analysis.
NumPy Used for numerical computing.
Pandas Used for data manipulation and analysis.
Matplotlib Used for data visualization.
Example:
import pandas as pd
data = {"Name":["A","B","C"],"Sales":[100,200,300]} df = [Link](data) print(df)
9. File Handling
Python allows reading and writing files.
Example:
file = open("[Link]","r") content = [Link]() print(content) [Link]()
File modes:
r – Read w – Write a – Append
10. Python for Data Analysts
Python is one of the most powerful tools for data analysts.
Typical workflow:
1. Import dataset 2. Clean data using Pandas 3. Analyze data 4. Create visualizations 5. Build insights
Example:
import pandas as pd
df = pd.read_csv("[Link]") print([Link]())
This displays the first few rows of the dataset.