The first edition of the book fails to discuss the main function, a function that is very commonly used, and one that we will be using.
The short article Python main function
discusses Python's main function and illustrates the way in which it is commonly invoked, as also shown below:
def main():
#call your functions from here.
if __name__ == '__main__':
main()
The first edition of the book says:
When you call a function with arguments, the values of those arguments
are copied to their corresponding parameters inside the function.
That is exactly how C works, but NOT exactly how Python works.
It is very IMPORTANT to understand exactly how Python works.
In Python, the argument has a reference to an object.
This reference is copied to the parameter,
so the parameter in the function refers to the same object that the
argument refers to.
This is called a shallow copy, when there are two references to the same object.
The rule given in the note in the book, that you should only use immutable objects for parameter default values, is good. I do not understand all the things that can happen if you use a mutable object as a parameter default object.
Some helpful suplemental reading can be found at
arbitrary number of parameters
(scroll down to the section called Arbitrary Number of Parameters)
very importment
scan
omit
omit
Read
Read
omit
omit
The examples in this section are a little confusing. If you do not do anything to change the way it works, variables inside the function are in a different namespace than variables that are not within that function.
omit
This is a good first example of a Python class.
The UppercaseException class is a child of the Exception class.
omit