Functions and Scopes
Learning Path ⋅ Skills: Python, Functions, Scope, Arguments, Parameters, Return, Globals
In this learning path, you’ll build a strong foundation in Python functions and scope. You’ll start by defining functions and working with parameters, including optional arguments, *args, **kwargs, and special / and * parameters. Then you’ll explore return values and None. From there, you’ll move into inner functions, closures, namespaces, the LEGB scope rule, and global variables.
Functions and Scopes
Learning Path ⋅ 10 Resources
Defining Functions and Parameters
Start with the basics of defining and calling Python functions. You’ll progressively work through optional arguments, *args and **kwargs, and special parameter syntax.
Course
Defining and Calling Python Functions
Learn how to define and call your own Python function. You'll also learn about passing data to your function and returning data from your function back to its calling environment.
Interactive Quiz
Defining and Calling Python Functions
Course
Defining Python Functions With Optional Arguments
Learn about Python optional arguments and how to define functions with default values. You'll also learn how to create functions that accept any number of arguments using args and kwargs.
Interactive Quiz
Using Python Optional Arguments When Defining Functions
Course
Python args and kwargs: Demystified
Learn how to use args and kwargs in Python to add more flexibility to your functions. You'll also take a closer look at the single and double-asterisk unpacking operators, which you can use to unpack any iterable object in Python.
Interactive Quiz
Python args and kwargs: Demystified
Tutorial
What Are Python Asterisk and Slash Special Parameters For?
Learn how to use the Python asterisk and slash special parameters in function definitions. With these symbols, you can define whether your functions will accept positional or keyword arguments.
Return Values and None
Once you know how to define functions and their parameters, learn what functions give back. Explore the return statement, its best practices, and Python’s None object.
Course
Using the Python return Statement Effectively
Learn how to use the Python return statement when writing functions. Additionally, you'll cover some good programming practices related to the use of return. With this knowledge, you'll be able to write readable, robust, and maintainable functions in Python.
Interactive Quiz
The Python return Statement
Course
Python's None: Null in Python
Learn about the NoneType object None, which acts as the null in Python. This object represents emptiness, and you can use it to mark default parameters and even show when you have no result. None is a tool for doing everything with nothing!
Inner Functions, Scope, and Namespaces
With a solid grasp of function basics, explore how Python resolves names. You’ll learn about inner functions, closures, the LEGB scope rule, namespaces, and global variables.
Course
Python Inner Functions
Learn what inner functions are in Python, how to define them, and what their main use cases are.
Interactive Quiz
Python Inner Functions: What Are They Good For?
Course
The LEGB Rule & Understanding Python Scope
In this step-by-step video course, you'll learn what scopes are, how they work, and how to use them effectively to avoid name collisions in your code.
Course
Navigating Namespaces and Scope in Python
Learn about Python namespaces, the structures used to store and organize the symbolic names created during execution of a Python program. You'll learn when namespaces are created, how they are implemented, and how they define variable scope.
Interactive Quiz
Namespaces and Scope in Python
Course
Working With Global Variables in Python Functions
Learn how to use global variables in Python functions using the global keyword or the built-in globals() function. You'll also learn a few strategies to avoid relying on global variables because they can lead to code that's difficult to understand, debug, and maintain.
Interactive Quiz
Using and Creating Global Variables in Your Python Functions
Congratulations on completing this learning path! You now have a thorough understanding of Python functions, from defining and calling them to managing scope and namespaces.
You’ve also completed the Python Core Basics section. Nice work! Your next step is the intermediate level:
Learning Path
Perfect Your Python Development Setup
16 Resources ⋅ Skills: VS Code, PyCharm, Virtual Environments, pyenv, Docker, Git, GitHub, IDEs, Code Editors, Claude Code, Cursor, Gemini CLI, GitHub Copilot
You might also be interested in these related learning paths:
Got feedback on this learning path?
Looking for real-time conversation? Visit the Real Python Community Chat or join the next “Office Hours” Live Q&A Session. Happy Pythoning!
