From the course: Python for Students

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Completing the task

Completing the task - Python Tutorial

From the course: Python for Students

Completing the task

- [Instructor] Using variables and functions together is really where programs start to come to life. When you call a function, it doesn't only have to print information, it can also process and return data, which we can then store in a variable. The value of function returns is called a return value. Let's get started with an example. In this example, we have a function called pizza name, which takes the name of a topping and prints out the name of the pizza. Let's go ahead and run it to see what it outputs. You can see that I called the function with the word cheese and it outputs the phrase cheese pizza. Instead of the function just printing the string, let's have it return the string so that we can store it in a variable. To do that, I'm going to remove the print function and instead use the keyword return. I can now store that string into a variable called pizza. We can now print the variable pizza in the same way, and we'll get the same output. Save the file and let's run it…

Contents