A default parameter gives a function a predefined value when the caller omits that argument. It lets one function handle both explicit and omitted inputs without requiring multiple definitions. section 6.0
Optional greeting
def hello(name='world'): return f'Hello, {name}!' hello() # 'Hello, world!' hello('out there') # 'Hello, out there!' hello('a', 'b') # TypeError: too many arguments The first parameter remains usable as a normal argument, but omission selects its default. A missing required parameter instead raises an error. section 6.0
Use a default when the number of parameters is known but one value is optional. Prefer it to *args when the function expects a specific optional value rather than an arbitrary number of values. section 6.2
Building flexible XML output
def myxml(tagname, content='', **kwargs): attrs = ''.join([f' {key}="{value}"' for key, value in kwargs.items()]) return f'<{tagname}{attrs}>{content}</{tagname}>' myxml('p') uses an empty string for omitted content, while callers can still provide content and keyword attributes. A similar pattern supports a summing function whose optional starting value defaults to 0. section 6.2 section 1.11



















