June 2002
Beginner to intermediate
640 pages
14h 24m
English
Remember that a function is a code block and that code blocks are collections of statements. Methods are similar to functions, and you define them the same way. The only difference is that, unlike functions, methods are associated with classes and are defined within them. Because of the similarities, the terms function and method will be used interchangeably in this section.
To define, or declare, a function or method, you enter the keyword def followed by the function name, a list of arguments enclosed in parentheses, and finally a colon. Next come the statements, which make up the body of the function. They start on a new line and, like all code blocks, are indented (if you don't ...
Read now
Unlock full access