{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ch04-title",
   "metadata": {},
   "source": [
    "# Functions"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ch04-overview",
   "metadata": {},
   "source": [
    "Functions let you name a reusable block of code and call it whenever you need that behavior.\n",
    "\n",
    "- Functions reduce repetition by giving a name to a reusable process\n",
    "- Parameters let a function work with different inputs\n",
    "- Return values let a function produce a result for later code to use\n",
    "- Scope controls where names are available\n",
    "- Recursion solves a problem by reducing it to smaller versions of itself\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "video",
   "metadata": {},
   "source": [
    "<h2>Video</h2>\n",
    "\n",
    "This short overview introduces Python functions and the basic idea of defining reusable code with `def`.\n",
    "\n",
    "```{raw} html\n",
    "<iframe width=\"100%\" height=\"400\" src=\"https://www.youtube.com/embed/9Os0o3wzS_I\" title=\"Python Functions Tutorial\" frameborder=\"0\" allowfullscreen></iframe>\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ch04-goals",
   "metadata": {},
   "source": [
    "<h2>Learning Goals</h2>\n",
    "\n",
    "By the end of this chapter, you will be able to:\n",
    "\n",
    "1. Define and call custom functions with `def`\n",
    "2. Use parameters, arguments, defaults, `*args`, and `**kwargs`\n",
    "3. Use `return` statements to send results back to the caller\n",
    "4. Explain local scope, function composition, docstrings, and basic lambda expressions\n",
    "5. Trace recursive function calls using base cases and recursive cases\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ch04-flow",
   "metadata": {},
   "source": [
    "<h2>Chapter Flow</h2>\n",
    "\n",
    "```{tableofcontents}\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "glossary",
   "metadata": {},
   "source": [
    "<h2>Glossary</h2>\n",
    "\n",
    "| Term | Meaning |\n",
    "| --- | --- |\n",
    "| Function | A named, reusable block of code |\n",
    "| Parameter | A variable name listed in a function definition |\n",
    "| Argument | A value passed into a function call |\n",
    "| Return value | The result a function sends back to the caller |\n",
    "| Scope | The region of a program where a name can be used |\n",
    "| Docstring | A string that documents what a function does |\n",
    "| Lambda | A small anonymous function written as a single expression |\n",
    "| `*args` | Syntax that collects extra positional arguments into a tuple |\n",
    "| `**kwargs` | Syntax that collects extra keyword arguments into a dictionary |\n",
    "| Recursion | A pattern where a function calls itself |\n",
    "| Base case | The stopping condition in a recursive function |\n",
    "| Recursive case | The part of a recursive function that calls itself on a smaller problem |"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0400-slides",
   "metadata": {},
   "source": [
    "<h2><a href=\"overview.html\" target=\"_blank\" style=\"color: var(--pst-color-link, #176de8);\">Chapter Overview Slides</a></h2>"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
