Functions and Scopes

Learning PathSkills: Python, Functions, Scope, Arguments, Parameters, Return, Globals

A person looking at a paper in front of a large sculpture that represents the different scopes in a Python program

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.

Title image for Defining and Calling Python Functions (Defining Your Own Python Function)

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.

Title image for Defining Python Functions With Optional Arguments (Using Python Optional Arguments When Defining 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.

Title image for Python args and kwargs: Demystified (Python args and kwargs: Demystified)

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.

Title image for What Are Python Asterisk and Slash Special Parameters For? (What Are Python Asterisk and Slash Special Parameters For?)

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.

Title image for Using the Python return Statement Effectively (The Python return Statement: Usage and Best Practices)

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.

Title image for The Python return Statement (The Python return Statement: Usage and Best Practices)

Interactive Quiz

The Python return Statement

Title image for Python's None: Null in Python (Null in Python: Understanding Python's NoneType Object)

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.

Title image for Python Inner Functions (Python Inner Functions)

Course

Python Inner Functions

Learn what inner functions are in Python, how to define them, and what their main use cases are.

Title image for The LEGB Rule & Understanding Python Scope (Python Scope & the LEGB Rule: Resolving Names in Your Code)

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.

Title image for Navigating Namespaces and Scope in Python (Namespaces and Scopes in Python)

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.

Title image for Working With Global Variables in Python Functions (Using and Creating Global Variables in Your Python Functions)

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.

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!

« Browse All Learning Paths