SlideShare a Scribd company logo
1 of 11
.
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
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
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
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
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
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
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
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
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
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
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 ==>

More Related Content

What's hot

CubeIT Tech - Algorithms
CubeIT Tech - AlgorithmsCubeIT Tech - Algorithms
CubeIT Tech - AlgorithmsKirill Suslov
 
Data Structure and Algorithms –Introduction.pptx
Data Structure and Algorithms –Introduction.pptxData Structure and Algorithms –Introduction.pptx
Data Structure and Algorithms –Introduction.pptxR S Anu Prabha
 
220 runtime environments
220 runtime environments220 runtime environments
220 runtime environmentsJ'tong Atong
 
1909 BERT: why-and-how (CODE SEMINAR)
1909 BERT: why-and-how (CODE SEMINAR)1909 BERT: why-and-how (CODE SEMINAR)
1909 BERT: why-and-how (CODE SEMINAR)WarNik Chow
 
Abstract data types
Abstract data typesAbstract data types
Abstract data typesHoang Nguyen
 
Lecture 10 semantic analysis 01
Lecture 10 semantic analysis 01Lecture 10 semantic analysis 01
Lecture 10 semantic analysis 01Iffat Anjum
 
Designing A Syntax Based Retrieval System03
Designing A Syntax Based Retrieval System03Designing A Syntax Based Retrieval System03
Designing A Syntax Based Retrieval System03Avelin Huo
 
Introduction to Eclipse
Introduction to Eclipse Introduction to Eclipse
Introduction to Eclipse Arpana Awasthi
 

What's hot (20)

Object reusability in python
Object reusability in pythonObject reusability in python
Object reusability in python
 
CubeIT Tech - Algorithms
CubeIT Tech - AlgorithmsCubeIT Tech - Algorithms
CubeIT Tech - Algorithms
 
Question bank unit i
Question bank unit iQuestion bank unit i
Question bank unit i
 
Wrapper classes
Wrapper classesWrapper classes
Wrapper classes
 
Data Structure and Algorithms –Introduction.pptx
Data Structure and Algorithms –Introduction.pptxData Structure and Algorithms –Introduction.pptx
Data Structure and Algorithms –Introduction.pptx
 
220 runtime environments
220 runtime environments220 runtime environments
220 runtime environments
 
Data structures
Data structuresData structures
Data structures
 
wrapper classes
wrapper classeswrapper classes
wrapper classes
 
Java tutorial part 3
Java tutorial part 3Java tutorial part 3
Java tutorial part 3
 
Regular Expressions
Regular ExpressionsRegular Expressions
Regular Expressions
 
1909 BERT: why-and-how (CODE SEMINAR)
1909 BERT: why-and-how (CODE SEMINAR)1909 BERT: why-and-how (CODE SEMINAR)
1909 BERT: why-and-how (CODE SEMINAR)
 
Namespaces
NamespacesNamespaces
Namespaces
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
Lecture 10 semantic analysis 01
Lecture 10 semantic analysis 01Lecture 10 semantic analysis 01
Lecture 10 semantic analysis 01
 
Designing A Syntax Based Retrieval System03
Designing A Syntax Based Retrieval System03Designing A Syntax Based Retrieval System03
Designing A Syntax Based Retrieval System03
 
Basic data-structures-v.1.1
Basic data-structures-v.1.1Basic data-structures-v.1.1
Basic data-structures-v.1.1
 
Ppt chapter06
Ppt chapter06Ppt chapter06
Ppt chapter06
 
Bert
BertBert
Bert
 
Introduction to Eclipse
Introduction to Eclipse Introduction to Eclipse
Introduction to Eclipse
 
Introduction java programming
Introduction java programmingIntroduction java programming
Introduction java programming
 

Similar to CLASS-XII Functions

5 cs xii_python_functions _ passing str list tuple
5 cs xii_python_functions _ passing str list tuple5 cs xii_python_functions _ passing str list tuple
5 cs xii_python_functions _ passing str list tupleSanjayKumarMahto1
 
3 cs xii_python_functions _ parameter passing
3 cs xii_python_functions _ parameter passing3 cs xii_python_functions _ parameter passing
3 cs xii_python_functions _ parameter passingSanjayKumarMahto1
 
Zero to Hero - Introduction to Python3
Zero to Hero - Introduction to Python3Zero to Hero - Introduction to Python3
Zero to Hero - Introduction to Python3Chariza Pladin
 
Userdefined functions brief explaination.pdf
Userdefined functions brief explaination.pdfUserdefined functions brief explaination.pdf
Userdefined functions brief explaination.pdfDeeptiMalhotra19
 
James Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on PythonJames Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on PythonCP-Union
 
summer training report on python
summer training report on pythonsummer training report on python
summer training report on pythonShubham Yadav
 
Python_Unit_2.pdf
Python_Unit_2.pdfPython_Unit_2.pdf
Python_Unit_2.pdfalaparthi
 
Using Python Libraries.pdf
Using Python Libraries.pdfUsing Python Libraries.pdf
Using Python Libraries.pdfSoumyadityaDey
 
Top Python Online Training Institutes in Bangalore
Top Python Online Training Institutes in BangaloreTop Python Online Training Institutes in Bangalore
Top Python Online Training Institutes in BangaloreSaagTechnologies
 
Functions2.pdf
Functions2.pdfFunctions2.pdf
Functions2.pdfprasnt1
 
An Overview Of Python With Functional Programming
An Overview Of Python With Functional ProgrammingAn Overview Of Python With Functional Programming
An Overview Of Python With Functional ProgrammingAdam Getchell
 
Programming in Civil Engineering_UNIT 2_NOTES
Programming in Civil Engineering_UNIT 2_NOTESProgramming in Civil Engineering_UNIT 2_NOTES
Programming in Civil Engineering_UNIT 2_NOTESRushikesh Kolhe
 
Programming in C sesion 2
Programming in C sesion 2Programming in C sesion 2
Programming in C sesion 2Prerna Sharma
 

Similar to CLASS-XII Functions (20)

5 cs xii_python_functions _ passing str list tuple
5 cs xii_python_functions _ passing str list tuple5 cs xii_python_functions _ passing str list tuple
5 cs xii_python_functions _ passing str list tuple
 
3 cs xii_python_functions _ parameter passing
3 cs xii_python_functions _ parameter passing3 cs xii_python_functions _ parameter passing
3 cs xii_python_functions _ parameter passing
 
Zero to Hero - Introduction to Python3
Zero to Hero - Introduction to Python3Zero to Hero - Introduction to Python3
Zero to Hero - Introduction to Python3
 
Userdefined functions brief explaination.pdf
Userdefined functions brief explaination.pdfUserdefined functions brief explaination.pdf
Userdefined functions brief explaination.pdf
 
James Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on PythonJames Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on Python
 
functions-.pdf
functions-.pdffunctions-.pdf
functions-.pdf
 
Python
PythonPython
Python
 
summer training report on python
summer training report on pythonsummer training report on python
summer training report on python
 
Python_Unit_2.pdf
Python_Unit_2.pdfPython_Unit_2.pdf
Python_Unit_2.pdf
 
Functions-.pdf
Functions-.pdfFunctions-.pdf
Functions-.pdf
 
Using Python Libraries.pdf
Using Python Libraries.pdfUsing Python Libraries.pdf
Using Python Libraries.pdf
 
Top Python Online Training Institutes in Bangalore
Top Python Online Training Institutes in BangaloreTop Python Online Training Institutes in Bangalore
Top Python Online Training Institutes in Bangalore
 
Functions2.pdf
Functions2.pdfFunctions2.pdf
Functions2.pdf
 
AI_2nd Lab.pptx
AI_2nd Lab.pptxAI_2nd Lab.pptx
AI_2nd Lab.pptx
 
An Overview Of Python With Functional Programming
An Overview Of Python With Functional ProgrammingAn Overview Of Python With Functional Programming
An Overview Of Python With Functional Programming
 
Python and You Series
Python and You SeriesPython and You Series
Python and You Series
 
Programming in Civil Engineering_UNIT 2_NOTES
Programming in Civil Engineering_UNIT 2_NOTESProgramming in Civil Engineering_UNIT 2_NOTES
Programming in Civil Engineering_UNIT 2_NOTES
 
C Programming - Refresher - Part II
C Programming - Refresher - Part II C Programming - Refresher - Part II
C Programming - Refresher - Part II
 
Programming in C sesion 2
Programming in C sesion 2Programming in C sesion 2
Programming in C sesion 2
 
Python functions
Python functionsPython functions
Python functions
 

Recently uploaded

Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxabhijeetpadhi001
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptx
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
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 ==>