Python
Simple, Powerful, and Versatile – The Swiss Army Knife of Programming
What is Python?
Python is a high-level, interpreted, general-purpose programming language emphasizing code
readability and simplicity. Created by Guido van Rossum in 1991, it is now one of the most popular
languages in the world, used in web development, data science, AI/ML, automation, and more.
Hello World
print("Hello, World!")
Variables & Data Types
name = "Alice" # str
age = 30 # int
price = 9.99 # float
is_active = True # bool
scores = [90, 85, 92] # list
info = {"city": "NY"} # dict
Control Flow
# If-elif-else
if age >= 18:
print("Adult")
elif age >= 13:
print("Teen")
else:
print("Child")
# For loop
for i in range(5):
print(i)
# List comprehension
squares = [x**2 for x in range(10)]
Functions
def greet(name, greeting="Hello"):
return f"{greeting}, {name}!"
print(greet("Bob"))
print(greet("Alice", "Hi"))
# Lambda
double = lambda x: x * 2
Classes & OOP
class Person:
def __init__(self, name, age):
[Link] = name
[Link] = age
def introduce(self):
return f"I'm {[Link]}, {[Link]} years old"
p = Person("Alice", 30)
print([Link]())
Common Libraries
• os / sys – Operating system and system interactions
• requests – HTTP requests (pip install requests)
• pandas – Data analysis and DataFrames
• numpy – Numerical computing with arrays
• matplotlib – Data visualization and charts
• flask / django – Web frameworks
• scikit-learn – Machine learning
Key Tips
• Use virtual environments: python -m venv env
• Install packages with pip: pip install package-name
• Python uses indentation (4 spaces) instead of braces
• Use f-strings for readable string formatting: f'Hello {name}'
• The Python REPL is great for quick experiments: just type python