Home
Python
Python Basics: A Practical Guide for Beginners
September 15, 2026
1 min

Table Of Contents

01
1. Variables & Data Types
02
2. Operators & Control Flow
03
3. Collections
04
4. Functions
05
5. Exceptions
06
6. Modules

If you’re getting into Backend Development, FastAPI, Automation, or AI, Python is a great language to start with.

1. Variables & Data Types

A variable stores a value. Python is dynamically typed, but type hints help in backend work.

name: str = "Daniel"
age: int = 25
price: float = 99.99
is_active: bool = True
data = 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}."

2. Operators & Control Flow

Use = to assign and == to compare.

a + b, a - b, a * b, a / b, a // b, a % b, a ** b
age >= 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.

3. Collections

List — ordered, mutable:

users = ["Daniel", "John", "Anna"]
users.append("Michael")
users[0], users[-1], len(users), "Daniel" in users
numbers[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")

4. Functions

def add(a: int, b: int) -> int:
return a + b
def greet(name: str = "Guest") -> str:
return f"Hello, {name}"

print() displays. return sends a value back.

5. Exceptions

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.

6. Modules

Split reusable code into files and import what you need.

from math_utils import add
import math as m

Avoid from module import *. Prefer clear imports as the project grows (routers, services, models).


Tags

#Python

Share

Related Posts

FastAPI
FastAPI Foundations
September 15, 2026
1 min
© 2026, All Rights Reserved.
Powered By

Social Media

githublinkedinyoutube