call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
CLASS-XII Functions
1. .
Class-XII Computer Science (083)
All the contents used as part of the slides are either self created or from the public domain or textbooks for Class XII.
This presentation is only used for leaning purpose only. Programs used in this presentation are based on Python 3.8.0.
Computational Thinking and Programming - 2
Working with Functions
S K Mahto, PGT (Computer Science)
J.N.V East Medinipur WB
2. Working with Functions
Working with
Functions
Topics to be covered
Scope,
Parameter passing,
Mutable/immutable properties of data objects,
Passing strings, lists, tuples, dictionaries to functions,
Default parameters,
Positional parameters,
Return values,
Functions using libraries: mathematical and string
functions.
Presented by : S K Mahto, PGT Computer Science
3. Working with Functions
Introduction
Scope
parameter passing
mutable/immutable properties of
data objects
passing strings, lists, tuples,
dictionaries to functions,
default parameters
positional parameters
return values
functions using libraries:
mathematical and str
Introduction
What is Function? : A function is a group of statements which performs a
specific task.
A function can –
have its name ,
have its argument(s),
perform certain task,
return a result;
Presented by : S K Mahto, PGT Computer Science
4. Working with Functions
Introduction
Scope
parameter passing
mutable/immutable properties of
data objects
passing strings, lists, tuples,
dictionaries to functions,
default parameters
positional parameters
return values
functions using libraries:
mathematical and str
Python Function Types
● Built-in functions
● Functions defined in modules / Modules
● User defined functions
Presented by : S K Mahto, PGT Computer Science
5. Working with Functions
Introduction
Scope
parameter passing
mutable/immutable properties of
data objects
passing strings, lists, tuples,
dictionaries to functions,
default parameters
positional parameters
return values
functions using libraries:
mathematical and str
Python Function Types
● Built-in functions – These are pre-defined functions
and are always available for use. You have used some of
them – len(), type(), int(), input() etc.
Presented by : S K Mahto, PGT Computer Science
6. Working with Functions
Introduction
Scope
parameter passing
mutable/immutable properties of
data objects
passing strings, lists, tuples,
dictionaries to functions,
default parameters
positional parameters
return values
functions using libraries:
mathematical and str
Python Function Types
● Functions defined in modules / Modules –
● A module is a file containing Python definitions (i.e. functions)
and statements.
● These functions can only be used when module is imported. For
example, if we want to use predefined functions inside a
module, say sqrt(), factorial(), we need to first import the
module math in our program.
Presented by : S K Mahto, PGT Computer Science
7. Working with Functions
Introduction
Scope
parameter passing
mutable/immutable properties of
data objects
passing strings, lists, tuples,
dictionaries to functions,
default parameters
positional parameters
return values
functions using libraries:
mathematical and str
Python Function Types
● Functions defined in modules / Modules –
Presented by : S K Mahto, PGT Computer Science
8. Working with Functions
Introduction
Scope
parameter passing
mutable/immutable properties of
data objects
passing strings, lists, tuples,
dictionaries to functions,
default parameters
positional parameters
return values
functions using libraries:
mathematical and str
Python Function Types
● User defined functions –
● These are defined by programmer. As programmers we can create our
own functions.
● To define a function keyword def is used.
● After the keyword comes an identifier i.e. name of the function,
followed by parenthesized list of parameters and the colon which
ends up the line.
● Next follows the block of statement(s) that are the part of function.
● return() statement exits and returns a value.
Presented by : S K Mahto, PGT Computer Science
9. Working with Functions
Introduction
Scope
parameter passing
mutable/immutable properties of
data objects
passing strings, lists, tuples,
dictionaries to functions,
default parameters
positional parameters
return values
functions using libraries:
mathematical and str
Python Function Types
● User defined functions –
Presented by : S K Mahto, PGT Computer Science
10. Working with Functions
Introduction
Scope
parameter passing
mutable/immutable properties of
data objects
passing strings, lists, tuples,
dictionaries to functions,
default parameters
positional parameters
return values
functions using libraries:
mathematical and str
Python Function Types
● User defined functions –
Presented by : S K Mahto, PGT Computer Science
11. Working with Functions
Introduction
Scope
parameter passing
mutable/immutable properties of
data objects
passing strings, lists, tuples,
dictionaries to functions,
default parameters
positional parameters
return values
functions using libraries:
mathematical and str
Defining Function & Calling a function
def fact(num):
f=1
for i in range(num,0,-1):
f=f*i
return(f)
print(fact(5))
Body of the
function
Name of
the
function
Argument of the function
Function call
OR
Calling function
Presented by : S K Mahto, PGT Computer Science
Keyword def is used
Function name - fact
Parameter – num
Body of function
return()
Here function calling ==>