Grade 12 Exam  >  Grade 12 Notes  >  Computer Science for Grade 12  >  Short Notes: Functions

Short Notes: Functions | Computer Science for Grade 12 PDF Download

Download, print and study this document offline
Please wait while the PDF view is loading
 Page 1


 
   
Working With Function 
 
Function: - A function is a subprogram that act on data and 
often return a value. 
 
Python function types:- 
 
1 = Built in function: - These are pre-define function and 
always available for use. You have used some of them like - 
len (), type (), int (), input () etc. 
 
2 = Function defined in modules: - These functions are pre-
defined in particular models and can only be used when the 
corresponding model is imported. 
For example: - If we want to find the square root of any 
number then we have import math module then call the 
function - sqrt () 
 
3 = User defined functions: - These are define by the 
programmer. As programmer you can create your own 
function. 
 
 
Defining function in python:-  
Page 2


 
   
Working With Function 
 
Function: - A function is a subprogram that act on data and 
often return a value. 
 
Python function types:- 
 
1 = Built in function: - These are pre-define function and 
always available for use. You have used some of them like - 
len (), type (), int (), input () etc. 
 
2 = Function defined in modules: - These functions are pre-
defined in particular models and can only be used when the 
corresponding model is imported. 
For example: - If we want to find the square root of any 
number then we have import math module then call the 
function - sqrt () 
 
3 = User defined functions: - These are define by the 
programmer. As programmer you can create your own 
function. 
 
 
Defining function in python:-  
 
   
Look figure carefully -- 
 
 
 
 
Function header: - The first line of the function definition 
that beings with keyword Def and ends with a colon (:), 
specifies the name of the function and its parameters. 
 
Parameters: - Variables that are listed within the 
parentheses of a function header. 
Page 3


 
   
Working With Function 
 
Function: - A function is a subprogram that act on data and 
often return a value. 
 
Python function types:- 
 
1 = Built in function: - These are pre-define function and 
always available for use. You have used some of them like - 
len (), type (), int (), input () etc. 
 
2 = Function defined in modules: - These functions are pre-
defined in particular models and can only be used when the 
corresponding model is imported. 
For example: - If we want to find the square root of any 
number then we have import math module then call the 
function - sqrt () 
 
3 = User defined functions: - These are define by the 
programmer. As programmer you can create your own 
function. 
 
 
Defining function in python:-  
 
   
Look figure carefully -- 
 
 
 
 
Function header: - The first line of the function definition 
that beings with keyword Def and ends with a colon (:), 
specifies the name of the function and its parameters. 
 
Parameters: - Variables that are listed within the 
parentheses of a function header. 
 
   
 
Function body: - The block of statement/indented - 
statement beneath function header that defines the action 
performed by the function.  
 
Indentation: - The blank space in the beginning of statement 
within a block. All statements within same block have same 
indentation. 
 
Flow of execution: - The flow of execution refers to the order 
in which statement are executed during a program run. 
 
For example: -  
def calcSum (x,y): 
        s = x + y 
        return s 
num1 = float (input ("Enter the first number: ")) 
num2 = float (input("Enter the second number : ")) 
sum = calSum (num1,num2) 
Page 4


 
   
Working With Function 
 
Function: - A function is a subprogram that act on data and 
often return a value. 
 
Python function types:- 
 
1 = Built in function: - These are pre-define function and 
always available for use. You have used some of them like - 
len (), type (), int (), input () etc. 
 
2 = Function defined in modules: - These functions are pre-
defined in particular models and can only be used when the 
corresponding model is imported. 
For example: - If we want to find the square root of any 
number then we have import math module then call the 
function - sqrt () 
 
3 = User defined functions: - These are define by the 
programmer. As programmer you can create your own 
function. 
 
 
Defining function in python:-  
 
   
Look figure carefully -- 
 
 
 
 
Function header: - The first line of the function definition 
that beings with keyword Def and ends with a colon (:), 
specifies the name of the function and its parameters. 
 
Parameters: - Variables that are listed within the 
parentheses of a function header. 
 
   
 
Function body: - The block of statement/indented - 
statement beneath function header that defines the action 
performed by the function.  
 
Indentation: - The blank space in the beginning of statement 
within a block. All statements within same block have same 
indentation. 
 
Flow of execution: - The flow of execution refers to the order 
in which statement are executed during a program run. 
 
For example: -  
def calcSum (x,y): 
        s = x + y 
        return s 
num1 = float (input ("Enter the first number: ")) 
num2 = float (input("Enter the second number : ")) 
sum = calSum (num1,num2) 
 
   
print("Sum of two given number is ",sum) 
 
 
 
Argument: - The values being passed through a function call 
statement are called argument (or actual parameters or 
actual argument). 
For example:-  
def calcSum ( x , y ): 
        s = x + y 
        return s 
 
print (calcSum ( 2 , 3 )) 
a = 5 
b = 6  
print (calcSum ( a , b )) 
d = 10 
print (calcSum ( 9 , d )) 
? Here a , b , d , 2 , 3 , 9 are “arguments” which is used in 
call function. 
 
Page 5


 
   
Working With Function 
 
Function: - A function is a subprogram that act on data and 
often return a value. 
 
Python function types:- 
 
1 = Built in function: - These are pre-define function and 
always available for use. You have used some of them like - 
len (), type (), int (), input () etc. 
 
2 = Function defined in modules: - These functions are pre-
defined in particular models and can only be used when the 
corresponding model is imported. 
For example: - If we want to find the square root of any 
number then we have import math module then call the 
function - sqrt () 
 
3 = User defined functions: - These are define by the 
programmer. As programmer you can create your own 
function. 
 
 
Defining function in python:-  
 
   
Look figure carefully -- 
 
 
 
 
Function header: - The first line of the function definition 
that beings with keyword Def and ends with a colon (:), 
specifies the name of the function and its parameters. 
 
Parameters: - Variables that are listed within the 
parentheses of a function header. 
 
   
 
Function body: - The block of statement/indented - 
statement beneath function header that defines the action 
performed by the function.  
 
Indentation: - The blank space in the beginning of statement 
within a block. All statements within same block have same 
indentation. 
 
Flow of execution: - The flow of execution refers to the order 
in which statement are executed during a program run. 
 
For example: -  
def calcSum (x,y): 
        s = x + y 
        return s 
num1 = float (input ("Enter the first number: ")) 
num2 = float (input("Enter the second number : ")) 
sum = calSum (num1,num2) 
 
   
print("Sum of two given number is ",sum) 
 
 
 
Argument: - The values being passed through a function call 
statement are called argument (or actual parameters or 
actual argument). 
For example:-  
def calcSum ( x , y ): 
        s = x + y 
        return s 
 
print (calcSum ( 2 , 3 )) 
a = 5 
b = 6  
print (calcSum ( a , b )) 
d = 10 
print (calcSum ( 9 , d )) 
? Here a , b , d , 2 , 3 , 9 are “arguments” which is used in 
call function. 
 
 
   
Parameters: - The values received in the function definition 
header are called parameter (or formal parameters or formal 
arguments). 
For example: - 
def calcSum ( x , y ): 
        : 
? Here x , y are “parameters”  
 
Passing parameters:-  
 
Python support three types of formal arguments/parameters: 
 
1:- Positional argument (required arguments): - When the 
functions call statement must match the number and order 
of arguments as define in the functions definition this is 
called the position argument matching. 
For example:-  
def check (a,b,c): 
       : 
Then possible functions call for this can be:- 
 
check ( x , y , z ) # 3 values( all variables) passed  
 
Read More
1 videos|25 docs|18 tests

Top Courses for Grade 12

1 videos|25 docs|18 tests
Download as PDF
Explore Courses for Grade 12 exam

Top Courses for Grade 12

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

Sample Paper

,

Short Notes: Functions | Computer Science for Grade 12

,

ppt

,

mock tests for examination

,

Free

,

pdf

,

Semester Notes

,

MCQs

,

Short Notes: Functions | Computer Science for Grade 12

,

past year papers

,

Short Notes: Functions | Computer Science for Grade 12

,

Important questions

,

study material

,

Previous Year Questions with Solutions

,

Exam

,

Extra Questions

,

Objective type Questions

,

shortcuts and tricks

,

Viva Questions

,

practice quizzes

,

Summary

,

video lectures

;