Revisiting functions
If you recall from Chapter 8, Introduction to Python, we looked at built-in functions, but we also looked at how we can define our own functions. We are now going to talk about arguments in functions and loops, as we delve deeper into how control flow works in Python.
Let's think about problems that involve range. The range takes two arguments: a minimum and a maximum. However, in Python, I should note that you can just give one argument, which then assumes your minimum is 0
. For example, if I write range(8)
, that's the same as range (0, 8)
. Take a look at what happens if you type range(2)
in the Python shell:
In Figure 10.3, you can see that the program interpreted the code as range(0, 2)
. But let's say you are always changing your range. Think of the range algorithm we wrote earlier. We are now going to rewrite it using a function. This function now has...