CSC108H5 Lecture Notes - Lecture 12: Structuring Element, Duplicate Code, Docstring
CSC108H5 verified notes
12/13View all
Document Summary
A function is a set of statements that performs a specific task. A function is a common structuring element allows that allows us to use a piece of code repeatedly in different parts of a program. Use of functions improve a program"s clarity and comprehensibility and makes it more efficient by reducing code duplication and breaking down complex tasks into manageable pieces. Function are also known as routines, subroutines, methods, procedures, subprograms. They can be passed as arguments, assigned to variables or stored in collections. A user defined python function or defined by def statement and follows the syntax: def function_name(parameter list): function body/statements. The indented statements make up the body of function and are executed when the. Once the function is called, parameters inside round brackets become arguments. Function bodies can have more than one return statement which may be placed anywhere within the function block.