How Can I Use Python Function?

Python is a block of function code that is used to perform a particular action. At this point, it will be clear to all of you what a function is.

A python function is a block of code that can take one or more input parameters, and can also execute and return a value. Functions are frequently used in Python programs.

Use Function in Python, Python Function Use, How to use Python Function

Function is a block of code Python Built-in and User defined define two types of function

  1. Built-in function
  2. User defined function

Built-in function

Such functions are pre-defined, and you can use them directly in your program, for example, the use of a print function to display messages on a screen or console.

User defined function

This type of function is defined by the programmer. As per your requirement you can define your name and functionality. In python you can define any function using def keyword.

How to create your own function in Python, also known as user defined function, please see the example below.

Example Code

#The Function Definition 
def sum(a,b): 
"add a and b" 
s=a+b 
print "Sum of two numbers is" 
print s 
#Calling the sum Function 
sum(20,50) 
sum(50,40)

Example Result

>>>
Sum of two numbers is
70
Sum of two numbers is
90
>>>