Defining function in Python

Defining function in Python

Hello everyone⚡, In this article, we will learn about how to define function in Python

Defining function in python

  • We can define a function using def keyword.
  • The logic of a function must be present inside the function.
  • The function executes only when we call.
  • Calling the function is a single statement.
  • Python source file can have more than one function definition.
  • Main function is not mandatory for python applications.
  • Once the function has been defined, we can call many times in any order.

raycast-untitled (10).png

Classification of function

Function classified into 4 types

  • No arguments and no return value.

Example -

def fun():   #no argument    
       ------
       ------
                   #no return value
  • With argument and no return values. Example -

    def fun(a,b):    #with argument
        ---------
        ---------
                           #no return value
    
  • With argument with return values. Example -

image.png

  • No arguments with return values. Example - image.png

Thank you for reading this article. I hope it was a great read for you. If you have any feedback please share it in the comment below. Also, if you find it helpful, please like and hit the follow button on the right top corner.

For a quick response, You can reach me on Twitter - twitter.com/Mahima13_dev