
Explore how Python functions work: define and call functions in the repl, distinguish function names from calls, and learn that print returns None.
Learn to pass functions as arguments to other functions, distinguish parameters from arguments, and call a function by name in a repeat five times example using print.
compare positional and keyword arguments by rewriting a greet function with host and guest, showing how host says hello to guest, and how order or naming affects calls.
Learn how to make Python function arguments optional by adding a default value, using a greeting parameter to customize output while preserving compatibility when omitted.
Explore how dictionaries differ from lists by focusing on key-value mappings rather than order, showing that two dictionaries are equal if their key-value pairs match, regardless of order.
Explore the mutable default value pitfall in Python, where a default list is shared across calls; fix by using None and creating a new list inside the function.
This course covers Python functions at intermediate and advanced levels. Once students have mastered the fundamentals of defining and calling functions, they're ready to start exploring more advanced topics. This course enables students to write more flexible and powerful functions and to be better placed to use functions in the standard library and third-party packages.
Functions allow you to package code so you can re-use it flexibly and efficiently whenever and wherever you need to. Understanding all the options available when creating parameters and passing arguments is key to be able to define and use functions effectively.
This course covers the following topics:
Positional and keyword arguments, and the requirements when mixing argument categories.
Optional arguments with default values
*args and **kwargs
Positional-only and keyword-only arguments using / and *
Generator functions using the `yield` keyword
---
About me, your instructor
I've been teaching Python for a decade. Before that, I worked as a physicist and used programming in my research work for over a decade.
My focus is on communicating clearly, in a friendly and relaxed manner. I'm the author of the The Python Coding Book (you can ask Google for a "python book" and you'll find this book as one of the first entries) and I have taught Python to individuals and corporations around the world.
And I'm approachable. You can ask me questions and I'll always reply, whether here on social media or anywhere else you can find me!