StudyLover
  • Home
  • Study Zone
  • Profiles
  • Typing Tutor
  • Contact us
  • Sign in
StudyLover Function Invoking
Download
  1. Python
  2. Pyhton MCA (Machine Learning using Python)
  3. Unit 3: Getting Started with Python: A Guide to Syntax, Data Structures, and OOP
Function Defining : Passing parameters
Unit 3: Getting Started with Python: A Guide to Syntax, Data Structures, and OOP

Invoking a function means to call or execute it. After you have defined a function (written the recipe), invoking it is the action that actually runs the code inside that function's block.

The syntax for invoking a function is to write its name followed by parentheses (). If the function requires parameters, you provide the values for those parameters, called arguments, inside the parentheses.


Example

Let's use the calculate_area function from our previous discussion.

1. The Definition (The Recipe)

This block of code creates the function but does not run it. It just tells Python what calculate_area means.

Python

def calculate_area(length, width):

    area = length * width

    return area

2. The Invocation (Following the Recipe)

This is the line that actually executes the code inside the calculate_area function.

Python

# Here, we are invoking the function with the arguments 10 and 5.

rectangle_area = calculate_area(10, 5)

When this line runs:

  • Python finds the calculate_area function.

  • The value 10 is passed to the length parameter.

  • The value 5 is passed to the width parameter.

  • The code inside the function (area = length * width) is executed.

  • The return statement sends the final value (50) back.

  • The returned value 50 is then assigned to the rectangle_area variable.

So, defining is creating the function, and invoking is using it.

 

 

Function Defining Passing parameters
Our Products & Services
  • Home
Connect with us
  • Contact us
  • +91 82955 87844
  • Rk6yadav@gmail.com

StudyLover - About us

The Best knowledge for Best people.

Copyright © StudyLover
Powered by Odoo - Create a free website