Python Function: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
m (Text replacement - "ions]] " to "ion]]s ") |
||
(23 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
A [[Python Function]] is a [[program function]] within a [[Python program]]. | A [[Python Function]] is a [[program function]] within a [[Python program]]. | ||
* <B | * <B>Context</U>:</B> | ||
** It can range from being a [[Python Built-in Function]] to being a [[Python User-defined Function]]. | ** It can range from being a [[Python Built-in Function]] to being a [[Python User-defined Function]] to being a [[Python Library Function]]. | ||
* <B | ** It can range from being a [[Python Named Function]] to being a [[Python Anonymous Function]]. | ||
** <code>def printme( str ):< | * <B>Example(s):</B> | ||
* <B | ** <code>def printme( str ): <BR> "This prints a passed string into this function" <BR> print str <BR> return</code> | ||
** a [[Python main() Function]]. | |||
** … | |||
* <B>Counter-Example(s):</B> | |||
** a [[Perl Function]]. | ** a [[Perl Function]]. | ||
* <B | * <B>See:</B> [[Python Data Structure]], [[PointStats.py]]. | ||
---- | ---- | ||
---- | ---- | ||
===2009=== | == References == | ||
=== 2009 === | |||
* http://www.tutorialspoint.com/python/python_functions.htm | * http://www.tutorialspoint.com/python/python_functions.htm | ||
** You can define [[Python Function| | ** You can define [[Python Function|function]]s to provide the required functionality. Here are simple rules to define a [[Python Function|function in Python]]: | ||
*** Function blocks begin with the keyword def followed by the function name and parentheses ( ( ) ). | *** Function blocks begin with the keyword def followed by the function name and parentheses (( )). | ||
*** Any input parameters or arguments should be placed within these parentheses. You can also define parameters inside these parentheses. | *** Any input parameters or arguments should be placed within these parentheses. You can also define parameters inside these parentheses. | ||
*** The first statement of a function can be an optional statement - the documentation string of the function or docstring. | *** The first statement of a function can be an optional statement - the documentation string of the function or docstring. | ||
Line 20: | Line 25: | ||
*** The statement return [expression] exits a function, optionally passing back an expression to the caller. A return statement with no arguments is the same as return None. | *** The statement return [expression] exits a function, optionally passing back an expression to the caller. A return statement with no arguments is the same as return None. | ||
===2006=== | === 2006 === | ||
* http://www.penzilla.net/tutorials/python/functions/ | * http://www.penzilla.net/tutorials/python/functions/ | ||
** Python is a little different from other languages like C/C++ and Java, in that [[Python Function| | ** Python is a little different from other languages like C/C++ and Java, in that [[Python Function|function]]s are not magic constructs, but values. Yes, [[Python Function|functions in Python]], are like integers in C. They are simply values and can be passed to other functions/object constructors, and so forth. | ||
---- | ---- | ||
__NOTOC__ | |||
[[Category:Concept]] | [[Category:Concept]] |
Latest revision as of 07:32, 22 August 2024
A Python Function is a program function within a Python program.
- Context:
- It can range from being a Python Built-in Function to being a Python User-defined Function to being a Python Library Function.
- It can range from being a Python Named Function to being a Python Anonymous Function.
- Example(s):
def printme( str ):
"This prints a passed string into this function"
print str
return- a Python main() Function.
- …
- Counter-Example(s):
- See: Python Data Structure, PointStats.py.
References
2009
- http://www.tutorialspoint.com/python/python_functions.htm
- You can define functions to provide the required functionality. Here are simple rules to define a function in Python:
- Function blocks begin with the keyword def followed by the function name and parentheses (( )).
- Any input parameters or arguments should be placed within these parentheses. You can also define parameters inside these parentheses.
- The first statement of a function can be an optional statement - the documentation string of the function or docstring.
- The code block within every function starts with a colon (:) and is indented.
- The statement return [expression] exits a function, optionally passing back an expression to the caller. A return statement with no arguments is the same as return None.
- You can define functions to provide the required functionality. Here are simple rules to define a function in Python:
2006
- http://www.penzilla.net/tutorials/python/functions/
- Python is a little different from other languages like C/C++ and Java, in that functions are not magic constructs, but values. Yes, functions in Python, are like integers in C. They are simply values and can be passed to other functions/object constructors, and so forth.