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

Enhance your Python skills by mastering functions and scope. This path covers defining functions, optional arguments, special parameters, return statements, None, namespaces, and global variables. Perfect for writing cleaner, more efficient code.

Functions and Scopes

Learning Path ⋅ 7 Resources

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 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.

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!

Title image for Navigating Namespaces and Scope in Python (Namespaces and Scope 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.

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