Python Notes 🐍
1. What is Python?
Python is a high-level, interpreted, general-purpose programming language known for its simple syntax
and readability.
Features
• Easy to learn and write
• Interpreted (no compilation needed)
• Cross-platform
• Huge standard library
• Used in Web, AI/ML, Data Science, Automation, DevOps
2. Installing & Running Python
Check Python version
python3 --version
Run Python
python3
Run a Python file
python3 [Link]
3. Variables & Data Types
Variables
x = 10
name = "Utsav"
pi = 3.14
1
Python is dynamically typed.
Basic Data Types
Type Example
int 10
float 3.14
str "hello"
bool True / False
None None
4. Input & Output
name = input("Enter your name: ")
print("Hello", name)
5. Operators
Arithmetic
+ - * / // % **
Comparison
== != > < >= <=
Logical
and or not
2
6. Conditional Statements
age = 18
if age >= 18:
print("Adult")
elif age > 13:
print("Teen")
else:
print("Child")
7. Loops
for loop
for i in range(5):
print(i)
while loop
i = 0
while i < 5:
print(i)
i += 1
break & continue
for i in range(10):
if i == 5:
break
8. Data Structures
List
nums = [1, 2, 3]
[Link](4)
3
Tuple (immutable)
t = (1, 2, 3)
Set
s = {1, 2, 3}
Dictionary
student = {
"name": "Utsav",
"age": 20
}
9. Functions
def add(a, b):
return a + b
print(add(2, 3))
Default Arguments
def greet(name="User"):
print("Hello", name)
10. Lambda Functions
square = lambda x: x * x
print(square(5))
4
11. Strings
text = "python"
print([Link]())
print([Link]())
print(text[::-1])
12. Modules & Packages
import math
print([Link](16))
Install Package
pip install requests
13. File Handling
with open("[Link]", "w") as f:
[Link]("Hello")
with open("[Link]", "r") as f:
print([Link]())
14. Exception Handling
try:
x = int("abc")
except ValueError:
print("Error occurred")
5
15. OOP (Object-Oriented Programming)
class Person:
def __init__(self, name):
[Link] = name
def greet(self):
print("Hello", [Link])
p = Person("Utsav")
[Link]()
16. Useful Built-in Functions
len(), type(), sum(), max(), min(), sorted()
17. Python Use Cases
• Automation (scripts, bots)
• Web Development (Django, Flask)
• Data Science (NumPy, Pandas)
• AI/ML (TensorFlow, PyTorch)
• DevOps & Cloud
18. How to Practice (Important 🔥)
• Solve problems on HackerRank / LeetCode
• Build small projects
• Read error messages carefully
• Use Google + Docs
19. Beginner Projects
• Calculator
• Number guessing game
• To-do list (CLI)
• Password generator
• Weather app (API)
6
If you want: - PDF notes - Interview-focused Python notes - God-level project roadmap - Python for
Data Science / AI
Tell me 👍