What is the syntax for creating, calling, and exiting subroutines in Python?

  • 5
    This question appears to be off-topic because it is about Python and has absolutely nothing to do with Raspberry Pi. – lenik Jul 22 '13 at 3:18

It's called a "function"; it begins with "def" and (usually) ends with "return".

Docs: http://docs.python.org/release/1.5.1p1/tut/functions.html

The keyword def introduces a function definition. It must be followed by the function name and the parenthesized list of formal parameters. The statements that form the body of the function start at the next line, indented by a tab stop. The first statement of the function body can optionally be a string literal; this string literal is the function's documentation string, or docstring. There are tools which use docstrings to automatically produce printed documentation, or to let the user interactively browse through code; it's good practice to include docstrings in code that you write, so try to make a habit of it.

Not the answer you're looking for? Browse other questions tagged or ask your own question.