Question-145: Please map following
Parameters: They are part of the function definitions
- Get all Questions and Answer from here
- You need to have paid subscription to access all questions
- Thanks for considering Python Certification Material
Answer:
Exp:
def calculate(x):
print("Your calculated value is ", x*x+10)
Parameters to functions
- As we have seen in previous calculate(x) function, we are passing one parameter, named as x.
- There are two things, which you need to remember
- Parameters: They are part of the function definitions. And remain only in function and not accessible outside function.
- Arguments: While invoking a function, you must have to pass exact same number of arguments as number of parameters defined on function. In case of calculate(x) has one parameter, so while invoking (calling) this function should have pass one argument.
Defining a function with 2 parameters and invoking with 2 arguments.
- In function definition, we are having two parameters ( a and b).
- While invoking this function we are passing two arguments (x,y)
- Hence, when function is called aà x and bà y
- It is not necessary that arguments and parameters has to have different name. Means in function definition you are having a,b and while calling you have arguments name as x,y
#Defining a function with two parameters def multiply(a,b): print("Multiplication is ", a*b)
i=0 while(i<10):
You can access to full explanation to question and answer from this page. |