DataDriven
LearnPracticeInterviewDiscussDaily
HelpContactPrivacyTermsSecurityiOS App

© 2026 DataDriven

Loading lesson...

  1. Home
  2. Learn
  3. Functions: Intermediate

Functions: Intermediate

Flexible, production-ready functions

Flexible, production-ready functions

Category
Python
Difficulty
intermediate
Duration
47 minutes
Challenges
0 hands-on challenges

Topics covered: Default Parameters, Multiple Return Values, Local vs Global Scope, *args for Variadics, **kwargs for Keywords

Lesson Sections

  1. Default Parameters (concepts: pyFuncDefault)

    Basic Default Values Default parameters are evaluated left to right at function definition time, not at call time. This distinction becomes important when we discuss the mutable default pitfall later in this section. For now, understand that each call either uses your provided value or falls back to the pre-defined default. Multiple Default Parameters Functions can have multiple default parameters. This is common in data processing functions where you want sensible defaults: Notice how the funct

  2. Multiple Return Values

    Python functions can return multiple values by returning a tuple. The caller can then unpack these values into separate variables. This pattern is cleaner than returning a dictionary or list when you have a fixed number of related values to compute and return together. In data engineering, you often need to compute several related metrics from the same data in a single pass. Rather than calling separate functions (which would iterate over the data multiple times), you compute everything in one f

  3. Local vs Global Scope (concepts: pyFuncScope)

    Scope determines where a variable is visible and accessible. Python has two main scopes: local (inside a function) and global (module level). Understanding scope prevents bugs where variables unexpectedly share or shadow each other. Scope bugs are especially tricky because the code often looks correct but behaves differently than expected. Every variable in Python lives in a specific scope. When you reference a variable name, Python searches scopes in a specific order to find it. Understanding t

  4. *args for Variadics (concepts: pyArgs)

    Basic *args Usage Mixing Regular and *args Unpacking with * Flexible Logging Example

  5. **kwargs for Keywords

    Basic **kwargs Usage Using *args and **kwargs Unpacking Dictionaries Configuration Example Forwarding Arguments This forwarding pattern is how decorators preserve function signatures. The wrapper function accepts any arguments and passes them through unchanged. The decorated function receives exactly what was passed to the wrapper, regardless of its parameter structure. This makes decorators universally applicable. Merging Dicts with ** This dictionary merging technique is common in configuratio

Related

  • All Lessons
  • Practice Problems
  • Mock Interview Practice
  • Daily Challenges