July 2017
Beginner to intermediate
420 pages
10h 56m
English
Let's talk about functions in Python. Like with other languages, you can have functions that let you repeat a set of operations over and over again with different parameters. In Python, the syntax for doing that looks like this:
def SquareIt(x): return x * xprint (SquareIt(2))
The output of the above code is as follows:
4
You declare a function using the def keyword. It just says this is a function, and we'll call this function SquareIt, and the parameter list is then followed inside parentheses. This particular function only takes one parameter that we'll call x. Again, remember that whitespace is important in Python. There's not going to be any curly brackets or anything enclosing this function. It's strictly defined ...
Read now
Unlock full access