Advertisement

Python Functions & Lambda

Previous Lesson 228 of 233 Next
Advertisement
Lesson Overview: Define reusable functions with def, default arguments, *args, **kwargs, and lambda.

Modular Functions & Lambdas

Use def name(params): to create functions and return values. Anonymous one-line functions use lambda x: x * 2.

  • Document functions with """Docstrings"""
  • Avoid mutable default arguments like def f(items=[]):

Functions & Lambda Sorting (Editable — type & Run)

Advertisement

Test Yourself With Exercises

Create an anonymous lambda adding 10 to x:

add10 = x: x + 10
Advertisement