What are docstrings and how do I use them to improve my code readability?

Docstrings are strings placed at the beginning of classes, functions, or .py files. They are implemented using three single quotes at the beginning and end. For example:

def Addition(a,b):

''' This function adds a and b together. '''

    return a+b

This docstring is then accessed in the interpreter using "Addition.doc"(no quotes). Docstrings are used to document how to use the class, function or script that it refers to, and so can improve code readability and maintainability.

CW
Answered by Callum W. Python tutor

2233 Views

See similar Python Mentoring tutors

Related Python Mentoring answers

All answers ▸

What is the difference between & and && operators?


Write a program that takes a value x and then outputs x Fibonnaci numbers. E.g. if x=6 output would be 1 1 2 3 5 8


Make a program that asks the user for a series of numbers until they either want to output the average or quit the program.


What is the difference between a for and a while loop?


We're here to help

contact us iconContact ustelephone icon+44 (0) 203 773 6020
Facebook logoInstagram logoLinkedIn logo

MyTutor is part of the IXL family of brands:

© 2026 by IXL Learning