From the course: Learning Python
Unlock this course with a free trial
Join today to access over 24,900 courses taught by industry experts.
Defining functions - Python Tutorial
From the course: Learning Python
Defining functions
- [Narrator] So far, we've been writing Python code in individual statements, but most larger programs are organized into reusable blocks of code known as functions. So functions give us a way of organizing our programs so they're more understandable and modular. And that's what we're going to learn about in this example. So here in my editor, I'm going to open up the functions start file. And if you're using Google CoLab, go ahead and create a code cell and go ahead and copy these three lines and paste them in there as a starting point. Okay, so let's take a look at the code from our very first program from way back in the beginning of the chapter. So here are these three lines, and these probably look familiar to you. Now suppose I wanted to use this code in multiple places in my program. It wouldn't make sense to just copy and paste the code everywhere because if I ever wanted to change how it works, I'd have to go change that code in lots of different places. A function allows me…