MISSION 411

Best Practices for Writing Functions

In our Python Fundamentals course, you learned the basics of functions, and practiced writing your own custom functions. But writing more complex functions, and functions that other people will be able to easily use, is a bit more complex.

To begin our Python Functions Advanced course, we'll cover some best practices that will make your code much easier to use, read, and maintain. Among other things, you'll learn how to document your code using docstrings, how to create functions that are easier to test, and how to set up default arguments.

In the first couple screens of this lesson, you will find out what docstrings are, and why it's a good idea to include them. At a high level, a docstring makes it much easier to tell what the function does and makes your code easier to decipher. After learning about docstrings, you will be learning two critical principles that make your functions easier to test and debug: Do One Thing and Don't Repeat Yourself. Towards the end of this lesson, you will also learn how Python passes arguments to functions, and the difference between mutable and immutable variables.

As you learn best practices for writing functions in Python, you’ll get to apply what you’ve learned from within your browser so that there's no need to use your own machine to do the exercises. The interactive Python environment used in this course includes answer checking so you can ensure that you've fully mastered each concept before learning the next concept.

Objectives

  • Learn best practices for writing functions in Python.
  • Learn how to create docstrings.
  • Learn the Don't Repeat Yourself principle and the Do One Thing principle.

Mission Outline

1. Introducting Docstrings
2. Retrieving Docstrings
3. Google Style Docstrings
4. Google Style Docstrings Continued
5. ​Don't Repeat Yourself
6. ​Do One Thing
7. ​Pass by Assignment
8. ​Pass by Assignment Continued
9. ​Mutable and Immutable Variables
10. ​​Mutable and Immutable Variables Continued
11. ​Next Steps
12. Takeaways

Course Info:

Intermediate

The median completion time for this course is 6 hours. View Details

This course requires a premium subscription. This course includes four missions.  It is the 27th course in the Data Scientist in Python path.

START LEARNING FREE

Take a Look Inside