{ "cells": [ { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# Chapter 2: Functions & Modularization (TL;DR)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "skip" } }, "source": [ "A user-defined **function** is a **named sequence** of statements that perform a computation.\n", "\n", "Functions provide benefits as they\n", "\n", "- make programs easier to comprehend and debug for humans as they give names to the smaller parts of a larger program (i.e., they **modularize** a code base), and\n", "- eliminate redundancies by allowing **reuse of code**.\n", "\n", "Functions are **defined** once with the `def` statement. Then, they may be **called** many times with the call operator `()`.\n", "\n", "They may process **parameterized** inputs, **passed** in as **arguments**, and output a **return value**.\n", "\n", "Arguments may be passed in by **position** or **keyword**. Some functions may even require **keyword-only** arguments.\n", "\n", "**Lambda expressions** create anonymous functions.\n", "\n", "Functions are a special kind of **callables**. Any object that may be **called** with the call operator `()` is a callable. Built-in functions and **constructors** are other kinds of callables.\n", "\n", "Core Python can be extended with code from either the **standard library** or **third-party** libraries.\n", "\n", "Outside Jupyter notebooks, Python code is put into **modules** that are grouped in **packages**." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.2" }, "livereveal": { "auto_select": "code", "auto_select_fragment": true, "scroll": true, "theme": "serif" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": false, "sideBar": true, "skip_h1_title": true, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": { "height": "calc(100% - 180px)", "left": "10px", "top": "150px", "width": "384px" }, "toc_section_display": false, "toc_window_display": false } }, "nbformat": 4, "nbformat_minor": 4 }