CHAPTER 8
Working with Functions
As in other programming languages, a function in Python is a stand-alone section of code that performs a particular task. In this chapter, you learn how functions work, put Python’s built-in functions to use, and create custom functions of your own.

Understanding Functions and Their Syntax
Understanding Function Parameters and Returns
Using Python’s Built-In Functions
Create a Function with Parameters and a Return
Create a Function with a Parameter But No Return
Create a Function with No Parameters But a Return
Create a Function with No Parameters and No Return
Understanding Functions and Their Syntax
A function is a stand-alone section of code that performs a particular task. For example, as you have seen earlier in this book, the input() function prompts the user to input text, while the print() function displays information on-screen. Python includes around 70 built-in functions that you can use immediately, and you can access other prebuilt functions by importing the modules that contain them. You can also create your own custom functions to perform operations that Python’s existing functions do not cover.
Understanding the Syntax of a Function

In Python, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access