3. Functions
• Functions are a construct to structure programs.
• Functions are used to utilize code in more than one place
in a program.
• The only way without functions to reuse code consists in
copying the code.
5. Functions
A function in Python is defined by a def statement. The
general syntax looks like this:
def function-name(Parameter list):
statements, i.e. the function body
• The parameter list consists of none or more parameters.
• The function body gets executed every time the function is
called.
8. return statement
• Function bodies can contain a return statement.
• Can be anywhere in the function body.
• Ends the execution of the function call and "returns" the
result, i.e. the value of the expression following the return
keyword, to the caller.
• If there is no return statement in the function code, the
function ends, when the control flow reaches the end of the
function body.
17. References
SPSE securitytube training by Vivek Ramachandran
SANS Python for Pentesters (SEC573)
Violent python
Security Power Tools
python-course.eu
----------------------------http://www.python-course.eu/functions.php
http://www.tutorialspoint.com/python/python_functions.htm
18. This work is licensed under the Creative Commons Attribution-NoDerivs 3.0 Unported License.
To view a copy of this license, visit
http://creativecommons.org/licenses/by-nd/3.0/
Copyright 2013 Mohammad Reza Kamalifard
All rights reserved.
Go to Kamalifard.ir/pysec101 to Download Slides and Course martials .