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.

Answered by Callum W. Python tutor

1614 Views

See similar Python Mentoring tutors

Related Python Mentoring answers

All answers ▸

What are the main data structures that I can use in Python


Sales is real Customers is integer startmainprog input Sales input Customers if ((Sales > 500) OR ((Sales > 300) AND (Customers>9))) then output “Bonus Awarded” else output “No Bonus” end if end subroutine. Sales = 600 Customers = 9, answer:


Write a simple Python program that asks a user to input their age and name and then return the text: "Hi my name is *NAME*, and I am *AGE* years old."


Generate an array of integers from 0 to 99 and split it into two smaller arrays. Each smaller array will contain half of the original.


We're here to help

contact us iconContact usWhatsapp logoMessage us on Whatsapptelephone icon+44 (0) 203 773 6020
Facebook logoInstagram logoLinkedIn logo
Cookie Preferences