Functions are defined with three components:
The header, which includes the
defkeyword, the name of the function, and any parameters the function requires. Here’s an example:def hello_world(): # There are no parameters
An optional comment that explains what the function does."""Prints 'Hello World!' to the console."""
The body, which describes the procedures the function carries out. The body is indented, just like conditional statements.print "Hello World!"
Here’s the full function pieced together:
def hello_world(): """Prints 'Hello World!' to the console.""" print "Hello World!"
Go ahead and create a function,
"Eggs!" to the console. Don’t forget to include a comment of your own choosing (enclose it in triple quotes!).