============================================= 5: Advanced Functions ============================================= Summary ============ - You can call functions using parameters as keyword parameters or positional parameters - Python allows you to set defaults for parameters - You can force parameters yo be positional only or keyword only using / and * - Specifying *name is a way of using a variable number of positional parameters - Any arguments supplied that are not used by positional parameters are stored in *name asa tuple - Specifying **kwname works in the same way as *name but any unused keyword arguments are stored in it as a dictionary - You can pass parameters as tuples or dictionaries by using the unpacking operators * and ** - Functions can return multiple values by returning a tuple which czn be unpacked into variables using destructuring assignment - Docstrings can be used to create rudimentary documentation for a function - Annotations can be applied to parameters and return values, usually to indicate the type Program ============ .. literalinclude:: programs/chapterFive.py :language: python Program Output ================= .. code-block:: console (docs-env) root@BMitchellLTOP:~/git/sphinx_students/source/programming_lang/book/programs# python3 chapterFive.py Extras received (stored as dictionary): {'gift_wrap': True} Subtotal: 40.0 Total: 40.0 Numbers received (stored as tuple): (1, 2, 3) Sum: 6 Extras received (stored as dictionary): {} Second Total: 47.25