fbpx

Learn Python Function in 2023

This article is a simple learning journey to Python Function. Function is one of the basic concepts to know and learn for any programing language. With that said it’s true for Python as well. A Python Function consists of four main parts.

  • Function name
  • Input passed to the function.
  • output returned by the function.
  • Function body or it’s logic.

In all programing language there is a way to write function, for python we write a function as mentioned below:

 
Python Function

  • def is must to start a function
  • addTwoNumber – name
  • (a,b) – input passed
  • return a+b – logic

Suppose you are creating a social media application like facebook , where you have to write a logic to show friends suggestion on each account . If you decide to write a function it will give you following benefit :

  • Faster Developemnt and easy maintenance: One person can work on this function and other can work of any other function and this way at one time two functionality can be developed.
  • Reusable: At the end you can call this function to anywhere on the page where you want to .
  • Easy to debug : If friend suggestion functionality is not working, you can check if the input and output of this function is right or not? If not, you know you have to just debug this function only and note whole code of the application.

Let’s learn to write your own Python Function with some examples


By tecksed

Leave a Reply

Your email address will not be published. Required fields are marked *

×