Skip to content

Module 1 · Introduction to Python — topic 6 of 14

Python in real-world development

How professional teams actually use Python: version control, virtual environments, tests, code review and deployment, and how a small script becomes maintained software.

Intermediate 14 min read·Lesson 6 of 306 in Python Programming

Learning objectives

  • Describe the life cycle of a real Python project
  • Explain why professionals use version control, tests and virtual environments
  • Write a small function with a matching test

Definition

How professional teams actually use Python: version control, virtual environments, tests, code review and deployment, and how a small script becomes maintained software.

Introduction

Writing code that works once on your own computer is the first step. Real-world development is about code that keeps working, that other people can change safely, and that runs reliably on other machines.

This lesson gives you a map of that process so the professional habits taught later in the course make sense from day one.

Why it matters

Most of a program’s life is spent being read, fixed and extended, not being written for the first time. Habits such as tests and clear structure make that work cheaper and safer, and employers look for them.

Detailed explanation

Version control: teams store code in Git so every change is recorded and can be reviewed or undone. Services such as GitHub host the shared copy.

Virtual environments: each project gets its own isolated set of installed packages, recorded in a requirements file, so it runs the same way on every machine.

Testing: small automated checks (often with pytest) confirm that functions return the right results. Tests run before every change is accepted.

Code review: another developer reads each change before it is merged, catching mistakes and sharing knowledge.

Deployment: the tested code is copied to a server or packaged for users, often automatically.

  • Plan the feature
  • Write code in small functions
  • Write tests
  • Commit to Git and open a review
  • Merge and deploy

Syntax

Python
def function_name(inputs):
return result
assert function_name(example) == expected
  • Professional code is organised into functions with clear inputs and outputs.
  • assert checks that a condition is true and stops the program if it is not.
  • Testing frameworks such as pytest build on the same idea.

Code examples

A small, testable function

Python
def add_gst(amount, rate=0.18):
return round(amount * (1 + rate), 2)
print(add_gst(100))
Output
118.0

Checking it with assert

Python
def add_gst(amount, rate=0.18):
return round(amount * (1 + rate), 2)
assert add_gst(100) == 118.0
assert add_gst(50, 0.05) == 52.5
print("All checks passed")
Output
All checks passed

More examples

Separating logic from input and output

Python
def grade(score):
if score >= 90:
return "A"
if score >= 75:
return "B"
if score >= 50:
return "C"
return "F"
tests = {95: "A", 75: "B", 60: "C", 10: "F"}
for score, expected in tests.items():
assert grade(score) == expected, score
print("grade() passed", len(tests), "tests")
Output
grade() passed 4 tests

Step-by-step explanation

  • grade(score) contains only the decision logic and returns a letter; it never prints.
  • Returning early with several if statements keeps each rule on its own line.
  • tests maps sample scores to the grade we expect, including the boundary 75.
  • The loop asserts each case; if one failed, the error would name the score.
  • Because the logic is separate from printing, it can be tested automatically.

Expected output

Running “Separating logic from input and output” prints exactly:

TextOutput
grade() passed 4 tests

Practical applications

  • Open-source projects on GitHub run their test suite automatically on every pull request.
  • Companies keep a requirements.txt or pyproject.toml so new developers can set up the project in minutes.
  • Web teams deploy Python services many times a day because tests catch mistakes early.

Best practices

  • Keep functions small and focused on one job.
  • Write a test for each rule, especially boundary values.
  • Commit small, related changes with clear messages.

Common mistakes

Mixing calculation and printing

Avoid

def grade(score):
print("A" if score >= 90 else "F")

Prefer

def grade(score):
return "A" if score >= 90 else "F"

A function that prints can’t easily be tested or reused. Return the result and let the caller decide what to do with it.

Installing packages globally for every project

Avoid

pip install requests (system-wide, for all projects)

Prefer

python -m venv .venv, activate it, then pip install requests

Global installs clash between projects. A virtual environment keeps each project’s packages separate.

Key takeaways

  • Real projects use Git, virtual environments, tests, review and deployment.
  • Return values from functions instead of printing inside them.
  • assert is the simplest form of an automated test.

Try it yourself

  1. 1
    Add a test for a score of exactly 90 and one for exactly 50 to the grade example.
    Show hint

    Boundary values are where mistakes usually hide.

  2. 2
    Write a function that converts kilometres to miles and two assert statements that check it.

Finished reading? Mark it complete to update your dashboard.

Suggested practice

8 questions cover the “Introduction to Python” module. Answers and explanations are revealed after you submit.

  • BeginnerPython is best described as which kind of language?
  • BeginnerWho created Python?
  • BeginnerHow does Python group statements into blocks?
Practise this module