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. By Shivang Yadav Last updated : January 05, 2024

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

In this program, we are defining a function named hi() and calling it.

# Function Definition
def hi():
    print("Hi")

# Function Calling
hi()

Output

The output of the above program is:

Hi

To understand the above program, you should have the basic knowledge of the following Python topics:

Python Basic Programs »

Related Programs

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.