🔥 BLACK FRIDAY SALE1 course ₹199·any 3 courses ₹399 for 3 months·ALL courses + 1 mock interview ₹599 for 6 monthsClaim offer →

Python · Functions, Closures and Iteration · Foundation · 28 min read

Python Functions, Arguments and Scope: Defaults, *args, **kwargs, Keyword-Only Parameters and LEGB

Design Python functions that are easy to call and hard to misuse. Learn how arguments are passed, positional versus keyword parameters, defaults and the mutable default trap, *args and **kwargs, positional-only and keyword-only markers, return values, docstrings, and the LEGB scope rules with global and nonlocal.

Python Functions, Arguments and Scope: Defaults, *args, **kwargs, Keyword-Only Parameters and LEGB: lesson illustration

A first look

  • Foundation level · 28 min read
  • 6 interview questions with model answers
  • Functions, Closures and Iteration · Python Mastery

You will learn to

  • Defining and calling functions; return values and None
  • How Python passes arguments (object references), and what that means for mutation
  • Positional, keyword, default, variadic, positional-only and keyword-only parameters
  • …and 3 more topics inside
Create an account to start

Create a free account to see what this lesson covers

  • Every free lesson in every section, in full
  • Track your progress and pick up where you left off
  • Free practice questions and an incident simulation
  • Takes under a minute: name, email and a password

No card needed. Full access to Python is a paid upgrade you can choose later.