Python Function: Difference between revisions

From GM-RKB
Jump to navigation Jump to search
No edit summary
 
m (Text replace - " " to " ")
Line 3: Line 3:
** 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]].
* <B><U>Example(s)</U>:</B>  
* <B><U>Example(s)</U>:</B>  
** <code>def printme( str ):</code> <P> <code>&nbsp;&nbsp;&nbsp; "This prints a passed string into this function"</code> <P> <code> &nbsp;&nbsp;&nbsp; print str</code> <P> <code>&nbsp;&nbsp;&nbsp; return</code>
** <code>def printme( str ):</code> <P> <code>   "This prints a passed string into this function"</code> <P> <code>     print str</code> <P> <code>   return</code>
* <B><U>Counter-Example(s)</U>:</B>  
* <B><U>Counter-Example(s)</U>:</B>  
** a [[Perl Function]].
** a [[Perl Function]].

Revision as of 07:54, 29 July 2013

A Python Function is a program function within a Python program.



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.

2006