Functions

Function names

Function names start with a lowercase letter. Most Python standards and frameworks state that function and method names should be in snake_case (all lowercase, words are separated with an underscore). In other programming languages, including PHP, camelCase (no spaces, second and subsequent words start with uppercase) is used for function and method names.

In Python, the def statement tells the computer that a function is about to be defined. Python does not require curly brackets to enclose the lines of code within a function. Instead, indentation is used to define the scope of the function. A colon: is placed directly after the function declaration (function name and parameter list). After the last line of code in the function, which will usually be a return statement, the indentation returns to the previous level.

Here is an example of a function that does not take any parameters. Notice that there is nothing between the brackets after the function name.

def hello_world():
return 'hello, world!' # The return value for this function is the string hello, world!