USER-DEFINE FUNCTION IN PYTHON PROGRAMING

USER-DEFINED FUNCTION IN PYTHON PROGRAMMING

java programming and c, c++, Matlab, Python, HTML, CSS programming language, and new techniques news and any history.
 USER-DEFINED FUNCTION 
When we are writing the code of a program, sometimes we have to type the same statement repeatedly. If we create a function, then we will not have to type the same code repeatedly, if we write the code that is used repeatedly in that function. For this reason, a user-defined function is created in a program.
USER-DEFINED FUNCTION IN PYTHON PROGRAMMING








The rules for defining a User-Define Function in Python are as follows: -
First of all, you have to choose a name for the function. You can choose the name of the function as you would choose the name of the variable. But when choosing a name, you have to keep in mind that the pre-defined function you used in the next lesson was called user-defined function, meaning that the name of the function you have created should be different from them.
Whatever name you choose for the function you will have to put the def word next to that name and the first bracket at the end of the name () is called parentheses in English and it is known only by the name of parentheses in the programming world] Will have
After the parentheses () sign, you have to place a colon: symbol.
def santosh():

  print("This is a example of user define function")
So above you saw how easily we created a function, but if you create a function in any python program, the code written in that function will not be executed. For the function to be executed, you have to call that function.

To call the function, you have to type the name of the function with the parentheses () sign. And you can call the function as often as you want in the same program.
def santosh():

  print("This is a example of user define function")

santosh()

PARAMETERS IN USER-DEFINE FUNCTION

What are the Parameters?
Parameters are a type of variable but they are created inside the parentheses () of the function.

For example, suppose that to create Parameters inside the function named ABC (), something would be of this type
Example 1:-
def abc(x,y):

  z=x+y

  print('x+y=',z)

abc(x=10,y=20
In the example above, you can see how in the abc () function we have created two Parameters named x and y and have also used them in the function. And later when we are calling abc () function, then we define the value of Parameters of the abc () function.

If you do not define the value of Parameters while calling the function, then the function will not execute and you will see an error message in the output.
 def abc(x,y):

  z=x+y

  print('x+y=',z)

# Function End

x=10
y=20
abc(x,y) # calling the function abc()
Scope Of Variable:-



















































































Comments