Python Crash Course

Doc Strings

Finally, you've learned about

  1. Data Types and Operators
  2. Control Flow
  3. Functional Programming

You now have all the tools you need in order to effectively read and write Python code. However, just as important as reading and writing Python code is knowing how to document it!

When your code gets really large you're going to have a lot of functions. Often times you'll be working with a team of developers. To them, it won't be immediately clear what the purpose of your functions are.

To cap off this course, you will end on a very light and easy note, documenting your code!

Documenting your code

Recall the function that you wrote to calculate the area of a rectangle.

def rectangle_area(length, width): area = length * width return area

To document this function, doc strings can be declared with triple double quotes "" . They usually follow this format.

"""INPUT://describes the arguments that the function accepts OUTPUT://describes what the function will do."""

This format can be applied to the rectangle_area function.

def rectangle_area(length, width): """INPUT:This function accepts two parameters: length and width.OUTPUT:This function calculates and returns the area based on the length and width provided by the user.""" area = length * width return area

‍Instead of having to read the code, a developer can quickly glance at your documentation and immediately recognize the purpose of your function. It is important to note that:

Doc strings and comments have zero impact on your code.

Congratulations, you're done!

C‍ongratulations on finishing the Python Crash Course! You should now feel confident in your abilities to read, write and even document Python code.

You learned about various data types and operators; controlling how your code is executed with conditional statements and loops; and re-organizing your code into functions to ensure code reusability. You've built a strong foundation in Python and I hope to see you in some of our advanced courses.

Till then, **Happy Coding!**‍‍

Feedback Summary
8 students





Written Reviews
There are no written reviews yet.