Loading video player…

Write Python Docstrings Effectively (Overview)

Writing clear, consistent docstrings in Python helps others understand your code’s purpose, parameters, and outputs. In this video course, you’ll learn about best practices, standard formats, and common pitfalls to avoid, ensuring your documentation is accessible to users and tools alike.

By the end of this video course, you’ll understand that:

  • Docstrings are strings used to document your Python code and can be accessed at runtime.
  • Python comments and docstrings have important differences.
  • One-line and multiline docstrings are classifications of docstrings.
  • Common docstring formats include reStructuredText, Google-style, NumPy-style, and doctest-style.
  • Antipatterns such as inconsistent formatting should be avoided when writing docstrings.
Download

Course Slides (.pdf)

2.4 MB
Download

Sample Code (.zip)

9.1 KB

00:00 Welcome to Write Python Docstrings Effectively. I’m Joseph, and in this video course, I’ll be taking you on a magical journey through the world of Python docstrings, their mystical ability to be code and documentation at the same time.

00:14 Documentation is an essential part of software development, and in Python, one of the best ways to document your code is with docstrings. You know those little, or not-so-little, pieces of text you find at the start of a function, class, or module.

00:27 You’ve no doubt read them before, and maybe you’ve even written a few, but are you writing them effectively? Are they too short, too long, too vague, too much?

00:38 These are the questions we’ll be asking and answering over the next six lessons.

00:43 In this course, you’ll learn to understand the purpose of docstrings, differentiate between docstrings and comments,

00:50 recognize and write Python docstrings in the most common formats, avoid common pitfalls when writing docstrings, and choose the appropriate docstring format for modules, classes, and functions.

01:03 So what should you know to get the most out of this course? Because this course isn’t about writing code in the usual sense, we only recommend that you have a good grasp on Python basics like functions, variables, data types, classes, and modules.

01:17 But if you’re still building your intuition around some of these concepts, I encourage you to stick around. That’s one of the beautiful things about documentation: whether you’re writing it or reading it, you’ll be learning something.

01:27 So let’s get started. Next up, we’ll begin building an understanding of Python docstrings from first principles.

Become a Member to join the conversation.