Defining and Calling Python Functions (Summary)
As applications grow larger, it becomes increasingly important to modularize code by breaking it up into smaller functions of manageable size. You now have the tools you need to do this.
In this course, you’ve learned:
- How to create a user-defined function in Python
- Several different ways you can pass arguments to a function
- How you can return data from a function to its caller
- How to add documentation to functions with docstrings and annotations
For more information about topics covered in this lesson, you can check out these resources:
- The Python return Statement: Usage and Best Practices | Real Python Article
- Pass by Reference in Python: Background and Best Practices | Real Python Article
- Python args and kwargs: Demystified | Real Python Article
- What Are Python Asterisk and Slash Special Parameters For? | Real Python Article
Congratulations, you made it to the end of the course! What’s your #1 takeaway or favorite thing you learned? How are you going to put your newfound skills to use? Leave a comment in the discussion section and let us know.
00:00 I hope you’ve enjoyed this course on how to write your own Python functions. Let’s look back at what we’ve done. As applications grow larger, it becomes increasingly important to modularize code by breaking it up into smaller functions of manageable size. Functions provide a means to do all that.
00:20 Functions allow for code to be reused, and parameters allow each invocation to be specialized from one call to the next. Using a function requires knowing its interface, which is the function name, any parameter values that it needs, and what value or values it returns.
00:39 You have learned how to create a user-defined function in Python. You’ve learned many ways that you can pass arguments to a function. Python provides a lot of flexibility for that, and we’ve spent a lot of lessons on the different means of passing arguments to a function.
01:01 We also saw how you can return data from a function to the place where it was called. And we learned how to use docstrings and annotations to provide documentation on how a function is to be used. Where can you go from here?
01:17
Well, there are tutorials and courses on the Python return
statement, usage and best practices. There’s more information on pass-by-reference in Python, background and best practices, and also args
and kwargs
demystified.
01:36 I hope you have enjoyed this course, and I look forward to joining you for another one.
aniketbarphe on Sept. 11, 2021
Great Course!
Premkumar on April 15, 2022
Thanks for the detailed course.
Brandon Hopkins on April 23, 2023
Thank you. You’re a great teacher.
ffh on Aug. 13, 2023
Great course. Very detailed. I will need some practice and come back to your course. Many thanks
alnah on Sept. 24, 2023
I’ve observed that the course is extensively structured, and really, it covers a lot and it’s great! But it allocates a considerable amount of time to elementary concepts, which may seem obvious to those who have advanced to this stage in the learning path. Additionally, some topics addressed seem tangential to the core objectives of the course.
At times, it appears that the instructor prioritizes showcasing its expertise in Python over delivering instructional content that is accommodating to beginners. The references to C++, for instance, can be perplexing for individuals still familiarizing themselves with Python syntax. This instructional approach also contributes to ambiguity regarding distinctions between side effects and return statements, as well as the concepts of mutable and immutable objects in function scope.
The course often lacks practical examples, giving the impression of being more theoretical, akin to a computer science course discussing functional programming through Python, rather than a hands-on guide on applying functional programming in Python. A particularly complex section delves into modifying annotations with the dunder method, leaving me seeking clarity on its real-world application, such as in API design.
Furthermore, the portion on enforcing type checking seems hurried and might benefit from further elaboration. Alternatively, considering its pace, it might be more beneficial to omit this section altogether, as it can be overwhelming, and leave it for another part of the learning path.
I trust this feedback will be constructive and assist in refining the course to better accommodate learners who are relatively new to these concepts. Despite the challenges, I managed to complete the course through additional videos and readings. I believe revising this course would be advantageous for subscribers to Real Python.
rwelk on April 18, 2024
Being new to python I found this course very informative. I intend to start Defining Your Own Python Function next on my learning path. Thank you for this video course.
Become a Member to join the conversation.
silvanog31560 on Aug. 9, 2021
Thank you for this course, it was great! I am sure that once I get some practice I will come back to review this again!