0% found this document useful (0 votes)
29 views

Function Python

Functions allow programmers to organize Python code into reusable chunks. A function is defined using the def keyword followed by a name and parameters in parentheses. The body of a function is indented and can contain multiple statements. Functions help break programs into smaller, modular pieces and avoid repetition by making code reusable. Built-in functions are included with Python while user-defined functions are created by programmers.

Uploaded by

arvie santos
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Function Python

Functions allow programmers to organize Python code into reusable chunks. A function is defined using the def keyword followed by a name and parameters in parentheses. The body of a function is indented and can contain multiple statements. Functions help break programs into smaller, modular pieces and avoid repetition by making code reusable. Built-in functions are included with Python while user-defined functions are created by programmers.

Uploaded by

arvie santos
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 7

FUNCTION

IN
PYTHON
FUNCTION

 Function is a group of related statements that perform a specific


task.
 A function is block of code which only runs when it is called.
 Function help break our program into smaller and modular chunks.
As our program grows larger and larger, function make it
organized and manageable.
 It avoids repetition and makes code reusable.
FUNCTION

Built-in function – function that are built into python.

User-defined / Programmer-defined function – function defined by


the users themselves.
CREATING A FUNCTION

 In Python a function is defined using the “def” keyword.


 A function name to uniquely identify it.
 Parameters (arguments) through which we pass values to a function. They
are optional. Any input parameters or arguments should be placed within
parentheses.
 A colon (:) to mark the end of function header.
 Optional documentation string (docstring) to describe what function does.
 Statements must have same indentation level (usually 4 spaces).
 An optional “return” statements to return a value from the function.
CREATING A FUNCTION
PARAMETERS (arguments)

 Information can be passed to function as parameter.


 Parameters are specified after the function name, inside the
parenthesis.
 You can add as many parameters as you want, just separate
them with comma.
PARAMETERS (arguments)

You might also like