×

Python Tutorial

Python Basics

Python I/O

Python Operators

Python Conditions & Controls

Python Functions

Python Strings

Python Modules

Python Lists

Python OOPs

Python Arrays

Python Dictionary

Python Sets

Python Tuples

Python Exception Handling

Python NumPy

Python Pandas

Python File Handling

Python WebSocket

Python GUI Programming

Python Image Processing

Python Miscellaneous

Python Practice

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. 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 »

Advertisement
Advertisement

Related Programs

Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

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