Home »
Python »
Python programs
Python program to declare a function and call it
Here, we will see a basic Python program to create a function and then call it.
Submitted by Shivang Yadav, on March 17, 2021
Functions in Python:
Functions are blocks of code (multiple program lines) that can perform a specific task like finding an area.
The function is used to reduce the line of code by having a code to perform a task and calling it again instead of writing multiple lines of code repeatedly.
A program can even take in values to perform the operation on, these are parameters.
Python provides many in-built functions and also allows the programmer to create their own functions.
Here, is the syntax for creating a function in Python
def functionName():
# code to be executed in the function
For a function to perform the task you need to call the function,
Python program to create and call a function
# Function Definition
def hi():
print("Hi")
# Function Calling
hi()
Output:
Hi
Python Basic Programs »