June 2000
Intermediate to advanced
556 pages
8h 45m
English
A function is a named collection of Python statements. Functions can take any number of arguments. The general form of a function is:
CD-ROM reference=5021.txt def <function name>(<arguments>): <statements>
In the following example, a function printHello is declared and then executed interactively.
CD-ROM reference=5022.txt >>> def printHello(): ... print "Hello" ... >>> printHello() Hello >>>
Note that the print "Hello" line is indented by one space relative to the def printHello(): line. Python's interactive prompt changes to a ... when it is expecting to see indented lines. To stop entering indented lines, press RETURN on a blank line. Python's prompt then returns to >>>.
In the following example, a function HoursFromDays ...
Read now
Unlock full access