-
Book Overview & Buying
-
Table Of Contents
Python Illustrated
By :
That was Chapter 6 already! Time for a little recap. In this chapter, we discovered the magic spells in Python: functions. Functions are snippets of code that you can run by calling their name. Calling a function can also be called invoking a function. This comes in handy when we want to reuse blocks of code throughout programs. Without functions, there would be a lot of duplicate code. They make your code base more readable and easier to maintain.
A function is declared with the keyword def, followed by the function name and parentheses. You could pass parameters into these parentheses if you feel like your function needs them, but some functions work just fine without them. Parameters are placeholders for values you pass in when you call the function. Look at this simple example where we passed in the parameter name:
def praise_dog(name):
print(f"{name} is a good dog!")
The code inside a function will not run unless you call the function. To call...