Skip to content

Python Functions




Python – Functions


As we read earlier about Python Operators . Now we will study about Functions in Python. In python programming language , Functions are a very important concept. If we create any one program, then we have to first create functions in it, it is very important to have a functions in big programs. We will not be able to run any program properly without creating functions. so lets start study about python functions.

 
 



What is a function in python ?

Function is a separate block of code that can be executed independently. It is used to reduce complexity of program. In other words, Function is a concept by which we can connects two or more machine or layers and also transfer data from one machine to another machine or layer.




How to create a function in python ?



Python function syntax :

def name of function ( comma separated argument ): 
            statement - - - - - - - - - - - - - 
            - - - - - - - - - - - - - - - -



Guidelines before creating any function :


  •  Thinking about about the naming of functions.

  •  Thinking about the input of functions.

  •  Thinking about the return type or output of function.



Example :

def sum(number1, number2):
    result = number1 + number2
    return result

The above code is a Non-executable code.




Two important functions in python are :

  • Print function : The print( ) function prints the specified message to the screen, or other standard output device. The message can be a string, or any other subject, the object will be converted into a string before written to the screen. 



Print function syntax :

print ( object(s), separator=separator, end=end, file=file )



Example :

print("Hello CodifyShow")



Output :

Hello CodifyShow


  •  Input function : The input function reads a line from input is known as Input function. Input function always return string data type.



Input function syntax :

input ( prompt )



Example :

Name = input("Enter your Name :")



Output :

Enter your Name :



>