Python Programming Exercises, Gently Explained
4
Most of the solutions involve writing functions that return values based on the arguments passed
to the function call. In these cases, you can write your code assuming that the arguments are always of
the expected data type. So for example, if your function expects an integer, it will have to handle
arguments like 42, 0, or -3 but doesn’t have to handle arguments like 3.14 or 'hello'.
Keep in mind that there is a difference between a
parameter and an
argument. When we
define a
function such as Exercise #3’s def isOdd(number):, the local variable number is a
parameter.
When we call this function with isOdd(42), the integer 42 is an
argument. The argument is passed to
the function and assigned as the value to the parameter. It’s easy to use ―parameter‖ and ―argument‖
interchangeably, but this book uses them in their correct technical sense.
Python is a practical language with many helpful functions in its standard library. Some exercises
will explicitly forbid you from using these functions. For example, Exercise #34, ―Uppercase Letters‖
tasks you to write code to convert a string to uppercase letters. Using Python’s built-in upper()
string method to do this for you would defeat the purpose of the exercise, so the
Exercise
Dostları ilə paylaş: