Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
59 views

Chapter 2 - Functions in Python

Functions allow blocks of code to be reused and help organize programs. There are built-in and user-defined functions. Functions can take parameters through positional, keyword, and default arguments. Parameters allow inputting flexible information into functions.

Uploaded by

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

Chapter 2 - Functions in Python

Functions allow blocks of code to be reused and help organize programs. There are built-in and user-defined functions. Functions can take parameters through positional, keyword, and default arguments. Parameters allow inputting flexible information into functions.

Uploaded by

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

Chapter 2 : Functions in Python

A function is a block of code which only runs when it is called.

Features / Advantages of using functions :

 Write once and run any where and any number of times
 Due to use of functions source code will reduce and affects execution
time i.e program will take less time to execute.
Classification of functions :

Built in Functions User defined Functions

Non parameterized functions Parameterized functions

Positional Para.. Keyword Para.. Default Para..

Built in Functions: ( eg sqrt(),pow(),abs(),speep(),floor(),ceil() etc )


Built in functions are also called as ready made functions.
To access built in functions respective module(container of functions) need
to import in program
User defined Functions:
User can create his own functions such a functions are called as user
defined functions.
Syntax for defining user defined functions
def function_name():
statement1
statement 2
……….
……….
function_name() -------------- function call
Or

Parameterized functions in python:


Python function accepts input information through parameters.
User may pass one or more than one parameters to function
Note: By default, a function must be called with the correct number of
arguments. i.e if your function expects 2 arguments, you have to call the
function with 2 arguments, not more, and not less.

Different ways of passing parameters to functions:


1. Positional Arguments

Note: by interchanging positions of parameters function will produce


different results and which is key drawback of of this method.
2. Keyword Arguments:
3. Default argument of function:

Passing List as an argument to function:

You might also like