Latest posts

10/recent/ticker-posts

Functions in python | python Functios | How to create an Function in Python

Functions is python

What is an Function : 

Python Functions is a block of statements that return the specific value.

The idea is to put some commonly or repeatedly done tasks together and make a function so that instead of writing the same code again and again for different inputs, we can do the function calls to reuse code contained in it over and over again.

How to create an Function :

Syntax : 


Creating a Python Function : 

We can create a python function using def keyword :

   
    # A Simple Python Function

    def myFunction():
        print("Hello World !")


Here we created a Function using def keyword with name 'myFunction'.
After that, in functions block we have printed a statement 'Hello World !'

Calling a Python Function :

After the creation of a Function to use, we need to call them.
We can able to call an Python Function by calling or we can say that by typing the Name of the function where we want to use it.


    # A Simple Python Function

    def myFunction():
        print("Hello World !")
   
    print("Hello Friends, our function says : ")
    print("")
    myFunction()        # Here we have called our Function using their Name !


output :


    Hello Friends, our function says :
   
    Hello World !


Types of Python Function :

1) Function without Argument/parameter
2) Function with Argument/Parameter

Function without Argument/Parameter :

Friends we have seen a function, which prints a statement 'Hello World'.

This type of Function is called as Function without Arguments/Parameters.

Syntax : 


    def functionName():
        # statement
        return expression


Example :



    # A Simple Python Function

    def myFunction():
        print("Hello World !")
   
    print("Hello Friends, our function says : ")
    print("")
    myFunction()        # Here we have called our Function using their Name !


output :


    Hello Friends, our function says :
   
    Hello World !




Function with Argument/Parameters : 

A Function, which takes some parameters from user to use it in their Statement to perform an operation is called as Function with Parameters.

Syntax : 


    def functionName(parameter):
        # statement
        return expression


Example :

   
    def addition(x,y):
        z = x + y
        print("Addition : "+str(z))

    # Addition of 2 Numbers :

    num1 = 10
    num2 = 20

    # Calling an Function...
    addition(num1,num2)


Output :


    Addition : 30






Python Function Project




Create a Calculator Using Python Function.






Download Source Code :



or 


Scan QR Code to Download the Source Code !

QR Code








Assingment :

Write a Program to Take the input (First Name, Middel Name, Last Name) from user and display them By using Pythond Function.










Also Visit


Post a Comment

0 Comments