Module 6: Python Functions

Intermediate 16 chapters

71. Introduction to Functions

Meet functions: named, reusable blocks of code. Learn why they exist, how to define and call a simple one, and how they make programs shorter, clearer and easier to fix.

Beginner25 min

72. Defining Functions

Learn how to define functions with def: naming, parameters, the body, return values, docstrings and local variables, with clear examples and common mistakes.

Beginner30 min

73. Calling Functions

Learn all the ways to call a function: with arguments, using the returned value, inside expressions, from other functions and in loops, plus what happens when the call is wrong.

Beginner25 min

74. Function Parameters

Learn what parameters are, how they differ from arguments, and how Python matches values to them, including the different kinds of parameters a function can have.

Beginner25 min

75. Positional Arguments

Understand how Python matches arguments to parameters by position, why order matters, and how to unpack lists and tuples into positional arguments.

Beginner25 min

76. Keyword Arguments

Learn to pass arguments by name, mix them with positional ones, unpack dictionaries with **, and use keyword-only parameters for clearer function calls.

Beginner25 min

77. Default Arguments

Learn how default parameter values make arguments optional, the rule about ordering, and the famous trap of using a mutable object such as a list as a default.

Beginner25 min

78. Variable-Length Arguments

Learn how a function can accept any number of positional or keyword arguments by using *args and **kwargs in its parameter list.

Intermediate25 min

79. *args and **kwargs

Learn how `*args` and `**kwargs` collect extra positional and keyword arguments, and how the same stars unpack lists and dictionaries when you call a function.

Intermediate25 min

80. Return Statement

Learn how the `return` statement sends a result back to the caller, ends the function early, returns several values as a tuple, and why a missing return gives `None`.

Beginner25 min

81. Scope of Variables

Understand where names live in Python: local, enclosing, global and built-in scopes, the LEGB lookup order, and why variables made inside a function disappear afterwards.

Intermediate25 min

82. Local and Global Variables

Learn where Python looks for names, the difference between local and global variables, and how to use the global and nonlocal keywords safely.

Intermediate25 min

83. Lambda Functions

Learn to write small anonymous functions with lambda, and use them with sorted, map, filter and max for short, clear code.

Intermediate25 min

84. Recursion

Understand recursion: functions that call themselves, with a base case and a recursive case. Learn factorial, Fibonacci, sums of nested lists, memoization and the recursion limit.

Intermediate30 min

85. Higher-Order Functions

Learn higher-order functions: functions that take functions as arguments or return them. Covers map, filter, sorted, functools.reduce and partial, and writing your own.

Intermediate30 min

86. map(), filter() and reduce()

Learn map(), filter() and functools.reduce(), three tools that apply a function to every item, keep only some items, or combine items into one value.

Intermediate30 min

Take the module test