If you’re getting into Backend Development, FastAPI, Automation, or AI, Python is a great language to start with.
A variable stores a value. Python is dynamically typed, but type hints help in backend work.
name: str = "Daniel"age: int = 25price: float = 99.99is_active: bool = Truedata = None
input() always returns a string — convert when needed:
age = int(input("Enter your age: "))message = f"My name is {name} and I am {age}."
Use = to assign and == to compare.
a + b, a - b, a * b, a / b, a // b, a % b, a ** bage >= 18 and is_active
if score >= 90:grade = "A"elif score >= 80:grade = "B"else:grade = "C"message = "Adult" if age >= 18 else "Minor"
for user in users:print(user)for i in range(1, 10, 2):print(i)while count < 5:count += 1
break stops a loop. continue skips the current iteration.
List — ordered, mutable:
users = ["Daniel", "John", "Anna"]users.append("Michael")users[0], users[-1], len(users), "Daniel" in usersnumbers[1:4]
Dict — key-value (like JSON):
user = {"id": 1, "name": "Daniel", "age": 25}user["name"]user.get("email", "No email")for key, value in user.items():print(key, value)
Set — unique values, no indexing:
unique = set([1, 2, 2, 3])a & b, a | b, a - b
Tuple — fixed, unpackable:
name, age, role = ("Daniel", 25, "admin")
def add(a: int, b: int) -> int:return a + bdef greet(name: str = "Guest") -> str:return f"Hello, {name}"
print() displays. return sends a value back.
try:age = int(input("Enter your age: "))except ValueError:print("Invalid age")finally:print("Finished")if age < 18:raise ValueError("User must be at least 18")
Don’t hide errors — handle them intentionally.
Split reusable code into files and import what you need.
from math_utils import addimport math as m
Avoid from module import *. Prefer clear imports as the project grows (routers, services, models).