Objective

Write reusable functions and organize code into modules.

Tools & Technologies

  • Python 3
  • def
  • import
  • __init__.py

Key Commands

def func(*args, **kwargs):
from module import func
import importlib
__all__ = ['func']

Lab Steps

01
Function Definition

Write functions with positional, keyword, *args, and **kwargs parameters.

02
Decorators

Create and apply function decorators for logging and timing.

03
Module Organization

Split code into modules and packages with proper imports.

04
docstrings

Write docstrings and use help() to access them.

Challenges Encountered

  • Circular imports break module loading
  • Mutable default arguments are shared across calls

Key Takeaways

  • Never use mutable objects as default parameter values
  • Use __all__ to control what a module exports