From the course: Python Theory for Network Engineers

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Python functions

Python functions

- [Instructor] So far, we have worked with Python built-in functions. Such as when we're converting integers to strings, or when we take the absolute value of a number. Those are built-in functions. In this section, we will learn how to define our own functions. What is the function? A function is a block of code we could group together to accomplish a certain task. The power of the function really resides in its repeatability. Because once the function is built, we could call it as many times as we would like. So to summarize, the main advantages of functions are modular and self-contained, and its reusability. The structure of the function is pretty straightforward. We use the def keyword to define a function. And give it a name. We use the parenthesis after the function name to indicate any parameters we want to give to the function. And these are optional. These could be positional or with keywords, as we'll…

Contents