Function in python

       Python program to demonstrate the function.

       Suppose,you have to store user name repeatedly for one particular statement. So,we can create function.

Functions  are using for doing specific job repeatedly. Functions are using for different arguments.

# defining the function def greet():
    print("Hello!")

# calling the function
>>>greet()
Hello!

# Here, we have not passed any information.
# we have just called the function which doing specific job.

# the function called using parenthesis ().

# the first statement line of function called docstring .
# docstring define what function is telling.

# The statement which belong to body of function are indented using space.
Parameter: it is      
           variable of function which store
some value about function .

def greet(name):
    print("Hello"+name)

# calling the function
>>>greet("vipul")
Hello vipul

# here name is parameter.
     
Arguments:it is specific  
value related to function.

In above example,"vipul " is information about user.

Note :sometimes         
arguments and parameters are used as same. Because both are related to same object.

Positional arguments:                       

           The argument which specify position of arguments. So,basically why we need order in argument ?

The python need which parameter specify to which argument.  So,for that positional argument need.

def greet(name,age):
    print("user name
is :" +name+",age
is "+age)

# calling the function with passing arguments.

>>>greet("vipul","19")   

Output:

user name is vipul,age is 19

# Here python specify that name is combine with "vipul" and age is combine with "19".

😀😃🎸

Leave a comment