Python Basics Guide
1. Introduction to Python
Python is a high-level, interpreted programming language known for its simplicity and readability. It's
widely used in web development, data science, automation, and more.
2. Variables and Data Types
Variables store data. Common types: int (10), float (3.14), str ('hello'), bool (True/False), list, tuple,
dict.
3. Control Flow
Use if/elif/else for decisions. Loops: for and while. Example:
for i in range(5): print(i)
4. Functions
Functions are reusable blocks of code. Define with def keyword:
def greet(name):
return 'Hello ' + name
5. Lists and Dictionaries
Lists store ordered data: [1, 2, 3]. Dicts store key-value pairs: {'name': 'Pretty', 'age': 20}
6. File Handling
Open and read/write files using open():
Python Basics Guide
with open('file.txt', 'r') as file:
content = file.read()
7. Modules and Packages
Use import to bring in standard or custom modules:
import math
print(math.sqrt(16))
8. Exception Handling
Handle errors with try/except:
try:
x=1/0
except ZeroDivisionError:
print('Cannot divide by zero')