Get startedGet started for free

Single-line docstrings

Docstrings are used to explain the purpose of a function. While the function name should be descriptive, this needs to be balanced with the length of the function name, so docstrings allow you to provide more detail.

In this exercise, you'll take the previously created clean_text function and add a single-line docstring.

This exercise is part of the course

Intermediate Python for Developers

View Course

Exercise instructions

  • Add a docstring stating """Swap spaces to underscores and convert text to lowercase.""".
  • Access the function's docstring using the appropriate attribute.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

def clean_string(text):
  
  # Add a single-line docstring
    
  
  no_spaces = text.replace(" ", "_")
  clean_text = no_spaces.lower()
  return clean_text

# Access the docstring
print(____)
Edit and Run Code