Python Basics
Variables, data types, control flow, functions, and file I/O. The universal starting point for AI, data science, and automation.
What it is & When to Use
Python is the primary language for data science, ML, automation, and AI development. Its readable syntax and extensive library ecosystem make it the right starting point for almost every technical learner today.
Essential Patterns
# Variables and types
name = "Arjun"
score = 87.5
passed = score >= 60
# List comprehension
squares = [x**2 for x in range(10)]
# Function with default arg
def greet(name, prefix="Hello"):
return f"{prefix}, {name}!"
# File I/O
with open("data.txt", "r") as f:
lines = f.readlines()
# Error handling
try:
result = int("abc")
except ValueError as e:
print(f"Error: {e}")
# Dictionary operations
student = {"name": "Priya", "cgpa": 8.4}
student["branch"] = "CSE"
keys = list(student.keys())
10 AI Learning Prompts
// Copy into ChatGPT or Claude to learn faster
- "Explain Python list comprehensions with 5 real examples."
- "What's the difference between a list and a tuple in Python?"
- "Show me Python file I/O patterns for reading CSV, JSON, and text files."
- "What are Python decorators and when should I use them?"
- "Explain Python generators vs. regular functions with memory usage examples."
- "What's the difference between *args and **kwargs? Show examples."
- "How does Python's GIL affect multi-threading?"
- "Show me how to use Python dataclasses with validation."
- "What are common Python anti-patterns I should avoid?"
- "How do I write Python unit tests with pytest for a simple function?"