Skip to content
IT Vizag
← Functions & Clean Code

▶ Sign up free for the video, slides & prompts

The lesson below is open to all. Enter your email once to unlock every video, slide deck, prompt and code example on this device.

Checking…

Writing readable code

Lesson 7 of 9 · 2 min read

Names, docstrings and the PEP 8 style guide.

🎬 Video version coming soon — read it now

Code is read far more often than it's written: by your teammates, your interviewer, and you in six months. Readable code is a professional skill, not decoration.

Names that explain

🔒 Code example: sign up free (above) to unlock it.

Good names remove the need for most comments.

Docstrings

A docstring is a string right under def that says what the function does:

🔒 Code example: sign up free (above) to unlock it.

help(bmi) shows it, and editors display it when you hover. Comments elsewhere should explain why, not repeat what.

Small functions, one job each

If a function scrolls off the screen, split it. A function called process_data that reads a file, cleans it, calculates and prints a report should be four functions.

No magic numbers

🔒 Code example: sign up free (above) to unlock it.

PEP 8: Python's style guide

The community agrees on one style, called PEP 8. The main points:

  • 4 spaces per indent, never tabs
  • snake_case for variables and functions, CapWords for classes, CAPS for constants
  • Spaces around operators: x = a + b, not x=a+b
  • Lines under about 80–100 characters
  • Two blank lines between top-level functions

You don't have to memorise it. Tools like ruff and black check and fix style automatically; you'll set them up in the Production Python course.

Simpler is better

🔒 Code example: sign up free (above) to unlock it.
Tip: Run import this in Colab to read "The Zen of Python". "Readability counts" is one of its lines, and Python developers really do live by it.

In one line

Use clear names, docstrings, small single-job functions and named constants, and follow PEP 8.

Saved on this device. Sign in to keep progress everywhere.

Share with a friend