What Is Function


What Is Function in Python?

✍: FYIcenter.com


A function, also called a method, in Python is a statement block waiting to be executed later with a function call expression.

A function can have the following elements:

  • Function name - A symbolic name that uniquely identifies this function within the context.
  • Parameter list - A list variables to share data objects with the calling statement. Parameter list is also called argument list.
  • Returning object - The data object returned to the calling statement.
  • Decorator list - A list of wrapper functions to be executed when this function is called.

Here is an example of a simple function definition statement block and a calling statement:

>>> def hello(name):
...     return "Hello "+name
>>> msg = hello("World")
>>> msg
'Hello World'

Note that in the Interactive mode, Python changes the prompt to "..." if the statement is not completed in the previous line.


'def' - Function Definition Statements

Defining Functions in Python

Defining Functions in Python

⇑⇑ Python Tutorials

2017-09-12, 1382🔥, 0💬