SlideShare a Scribd company logo
1 of 27
FUNCTIONS
Learning outcomes:
 What is Function?
 Defining a Function
 Calling a Function
 Passing by Reference vs Passing by Value
 Ways to write a function
 Types of functions
 Anonymous Functions
 Recursive Function
Functions
 A function is a set of statements sorted out together to play out a specific task.
 Python has a enormous number of in-built functions and the user can also make their own
functions.
 Functions are utilized to sensibly break our code into less complex parts which become simple to
keep up and comprehend.
 A developer develops a function to abstain from rehashing a similar assignment, or reduce
complexity.
 In Python, function is a group of related statements that perform a specific task.
 Functions help break our program into smaller and modular chunks.
 Furthermore, it avoids repetition and makes code reusable.
Defining a Function
 You can define functions to provide the required functionality.
 Here are simple rules to define a function in Python.
 Function blocks begin with the keyword def followed by the function name and parentheses.
 Any input parameters or arguments should be placed within these parentheses.
 You can also define parameters inside these parentheses.
 The first statement of a function can be an optional statement - the documentation string of
the function or docstring.
 The code block within every function starts with a colon (:) and is indented.
 The statement return [expression] exits a function, optionally passing back an expression to the
caller.
 A return statement with no arguments is the same as return None.
 Syntax of a Function:
def function_name(parameters): statement(s)
Indentation should be maintained
Defining a Function
 Example of Function:
def pow (a, b) :
result = a**b
print(a,"raised to the power", b, "is", result)
Here, we created a function called pow(). It takes two arguments, finds the first argument raised
to the power of second argument and prints the result in appropriate format.
Calling a Function
 Defining a function only gives it a name, specifies the parameters that are to
be included in the function and structures the blocks of code.
 Once a function is defined, you may call by it’s function name with the
required arguments/parameters.
 Following is the example to call pow() function:
def pow (a, b) :
result = a**b
print(a,"raised to the power", b, "is", result)
pow(5,3)
Passing by Reference Versus Passing by
Value
 Python utilizes a system, which is known as “Call by Object Reference” or
“Call by assignment”.
 In the event that you pass arguments like whole numbers, strings or tuples to
a function, the passing is like call-by-value because you can not change the
value of the immutable objects being passed to the function.
 Whereas passing mutable objects can be considered as call by reference
because when their values are changed inside the function, then it will also
be reflected outside the function.
Passing by Reference Versus Passing by
Value
 Example:
def changeme( mylist ):
mylist = [1,2,3,4]; # This would assig new reference in mylist
print ("Values inside the function: ", mylist)
# Now you can call changeme function
mylist = [10,20,30];
changeme( mylist );
print ("Values outside the function: ", mylist)
 Example:
def changeme( mylist ):
mylist.append([1,2,3,4]);
print ("Values inside the function: ", mylist)
# Now you can call changeme function
mylist = [10,20,30];
changeme( mylist );
print ("Values outside the function: ", mylist)
Ways to write a function
Anonymous Functions
 These functions are called anonymous because they are not declared in the
standard manner by using the def keyword.
 You can use the lambda keyword to create small anonymous functions.
 Lambda forms can take any number of arguments but return just one value in
the form of an expression.
 They cannot contain commands or multiple expressions.
 An anonymous function cannot be a direct call to print because lambda
requires an expression
Syntax:
lambda parameter_1,parameter_2,….parameter_n :
expression
 Program to add two numbers using function
def sum(n1,n2):
s=n1+n2
return s
x=int(input("Enter the number"))
y=int(input("Enter the number"))
print(sum(x,y))
Program to add two numbers using lambda function :
sum = lambda n1,n2 : n1+n2
x=int(input("Enter the number"))
y=int(input("Enter the number"))
print(sum(x,y)
Recursive Functions
 A function that calls itself is called a recursive function and this technique is known as recursion.
 This special programming technique can be used to solve problems by breaking them into
smaller and simpler sub-problems.
 Recursion is a common mathematical and programming concept. It means that a function calls
itself.
 This has the benefit of meaning that you can loop through data to reach a result.
 An example can help clarify this concept. Let us take the example of finding the factorial of a
number.
 Factorial of a positive integer number is defined as the product of all the integers from 1 to
that number.
 For example, the factorial of 5 (denoted as 5!) will be 1*2*3*4*5 = 120
 This problem of finding factorial of 5 can be broken down into a sub-problem of multiplying the
factorial of 4 with 5.
5! = 5*4!
Or more generally,
n! = n*(n-1)!
Now we can continue this until we reach 0! which is 1.
Thank you

More Related Content

Similar to Functions Guide

Python programming - Functions and list and tuples
Python programming - Functions and list and tuplesPython programming - Functions and list and tuples
Python programming - Functions and list and tuplesMalligaarjunanN
 
C programming language working with functions 1
C programming language working with functions 1C programming language working with functions 1
C programming language working with functions 1Jeevan Raj
 
Python Function.pdf
Python Function.pdfPython Function.pdf
Python Function.pdfNehaSpillai1
 
FUNCTIONS IN R PROGRAMMING.pptx
FUNCTIONS IN R PROGRAMMING.pptxFUNCTIONS IN R PROGRAMMING.pptx
FUNCTIONS IN R PROGRAMMING.pptxSafnaSaff1
 
Python_Unit_2.pdf
Python_Unit_2.pdfPython_Unit_2.pdf
Python_Unit_2.pdfalaparthi
 
Module 3-Functions
Module 3-FunctionsModule 3-Functions
Module 3-Functionsnikshaikh786
 
Amit user defined functions xi (2)
Amit  user defined functions xi (2)Amit  user defined functions xi (2)
Amit user defined functions xi (2)Arpit Meena
 
INTRODUCTION TO PYTHON PROGRMMING AND FUNCTIONS
INTRODUCTION TO PYTHON PROGRMMING AND FUNCTIONSINTRODUCTION TO PYTHON PROGRMMING AND FUNCTIONS
INTRODUCTION TO PYTHON PROGRMMING AND FUNCTIONSKalaivaniD12
 
Functions2.pdf
Functions2.pdfFunctions2.pdf
Functions2.pdfprasnt1
 
04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptx04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptxManas40552
 

Similar to Functions Guide (20)

Chapter 1.ppt
Chapter 1.pptChapter 1.ppt
Chapter 1.ppt
 
Python programming - Functions and list and tuples
Python programming - Functions and list and tuplesPython programming - Functions and list and tuples
Python programming - Functions and list and tuples
 
Functions
FunctionsFunctions
Functions
 
C programming language working with functions 1
C programming language working with functions 1C programming language working with functions 1
C programming language working with functions 1
 
Python Function.pdf
Python Function.pdfPython Function.pdf
Python Function.pdf
 
FUNCTIONS IN R PROGRAMMING.pptx
FUNCTIONS IN R PROGRAMMING.pptxFUNCTIONS IN R PROGRAMMING.pptx
FUNCTIONS IN R PROGRAMMING.pptx
 
Python_Unit_2.pdf
Python_Unit_2.pdfPython_Unit_2.pdf
Python_Unit_2.pdf
 
Module 3-Functions
Module 3-FunctionsModule 3-Functions
Module 3-Functions
 
Python functions
Python functionsPython functions
Python functions
 
Amit user defined functions xi (2)
Amit  user defined functions xi (2)Amit  user defined functions xi (2)
Amit user defined functions xi (2)
 
INTRODUCTION TO PYTHON PROGRMMING AND FUNCTIONS
INTRODUCTION TO PYTHON PROGRMMING AND FUNCTIONSINTRODUCTION TO PYTHON PROGRMMING AND FUNCTIONS
INTRODUCTION TO PYTHON PROGRMMING AND FUNCTIONS
 
functions- best.pdf
functions- best.pdffunctions- best.pdf
functions- best.pdf
 
Lecture 08.pptx
Lecture 08.pptxLecture 08.pptx
Lecture 08.pptx
 
Functions2.pdf
Functions2.pdfFunctions2.pdf
Functions2.pdf
 
04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptx04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptx
 
3. functions modules_programs (1)
3. functions modules_programs (1)3. functions modules_programs (1)
3. functions modules_programs (1)
 
Python-Functions.pptx
Python-Functions.pptxPython-Functions.pptx
Python-Functions.pptx
 
4. function
4. function4. function
4. function
 
Function
FunctionFunction
Function
 
User Defined Functions
User Defined FunctionsUser Defined Functions
User Defined Functions
 

Recently uploaded

(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 

Recently uploaded (20)

(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 

Functions Guide

  • 2. Learning outcomes:  What is Function?  Defining a Function  Calling a Function  Passing by Reference vs Passing by Value  Ways to write a function  Types of functions  Anonymous Functions  Recursive Function
  • 3. Functions  A function is a set of statements sorted out together to play out a specific task.  Python has a enormous number of in-built functions and the user can also make their own functions.  Functions are utilized to sensibly break our code into less complex parts which become simple to keep up and comprehend.  A developer develops a function to abstain from rehashing a similar assignment, or reduce complexity.  In Python, function is a group of related statements that perform a specific task.  Functions help break our program into smaller and modular chunks.  Furthermore, it avoids repetition and makes code reusable.
  • 4. Defining a Function  You can define functions to provide the required functionality.  Here are simple rules to define a function in Python.  Function blocks begin with the keyword def followed by the function name and parentheses.  Any input parameters or arguments should be placed within these parentheses.  You can also define parameters inside these parentheses.  The first statement of a function can be an optional statement - the documentation string of the function or docstring.
  • 5.  The code block within every function starts with a colon (:) and is indented.  The statement return [expression] exits a function, optionally passing back an expression to the caller.  A return statement with no arguments is the same as return None.  Syntax of a Function: def function_name(parameters): statement(s) Indentation should be maintained
  • 6.
  • 7. Defining a Function  Example of Function: def pow (a, b) : result = a**b print(a,"raised to the power", b, "is", result) Here, we created a function called pow(). It takes two arguments, finds the first argument raised to the power of second argument and prints the result in appropriate format.
  • 8. Calling a Function  Defining a function only gives it a name, specifies the parameters that are to be included in the function and structures the blocks of code.  Once a function is defined, you may call by it’s function name with the required arguments/parameters.  Following is the example to call pow() function: def pow (a, b) : result = a**b print(a,"raised to the power", b, "is", result) pow(5,3)
  • 9. Passing by Reference Versus Passing by Value  Python utilizes a system, which is known as “Call by Object Reference” or “Call by assignment”.  In the event that you pass arguments like whole numbers, strings or tuples to a function, the passing is like call-by-value because you can not change the value of the immutable objects being passed to the function.  Whereas passing mutable objects can be considered as call by reference because when their values are changed inside the function, then it will also be reflected outside the function.
  • 10. Passing by Reference Versus Passing by Value  Example: def changeme( mylist ): mylist = [1,2,3,4]; # This would assig new reference in mylist print ("Values inside the function: ", mylist) # Now you can call changeme function mylist = [10,20,30]; changeme( mylist ); print ("Values outside the function: ", mylist)
  • 11.  Example: def changeme( mylist ): mylist.append([1,2,3,4]); print ("Values inside the function: ", mylist) # Now you can call changeme function mylist = [10,20,30]; changeme( mylist ); print ("Values outside the function: ", mylist)
  • 12. Ways to write a function
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21. Anonymous Functions  These functions are called anonymous because they are not declared in the standard manner by using the def keyword.  You can use the lambda keyword to create small anonymous functions.  Lambda forms can take any number of arguments but return just one value in the form of an expression.  They cannot contain commands or multiple expressions.  An anonymous function cannot be a direct call to print because lambda requires an expression
  • 23.
  • 24.  Program to add two numbers using function def sum(n1,n2): s=n1+n2 return s x=int(input("Enter the number")) y=int(input("Enter the number")) print(sum(x,y)) Program to add two numbers using lambda function : sum = lambda n1,n2 : n1+n2 x=int(input("Enter the number")) y=int(input("Enter the number")) print(sum(x,y)
  • 25. Recursive Functions  A function that calls itself is called a recursive function and this technique is known as recursion.  This special programming technique can be used to solve problems by breaking them into smaller and simpler sub-problems.  Recursion is a common mathematical and programming concept. It means that a function calls itself.  This has the benefit of meaning that you can loop through data to reach a result.  An example can help clarify this concept. Let us take the example of finding the factorial of a number.  Factorial of a positive integer number is defined as the product of all the integers from 1 to that number.  For example, the factorial of 5 (denoted as 5!) will be 1*2*3*4*5 = 120
  • 26.  This problem of finding factorial of 5 can be broken down into a sub-problem of multiplying the factorial of 4 with 5. 5! = 5*4! Or more generally, n! = n*(n-1)! Now we can continue this until we reach 0! which is 1.