ADVERTISEMENT
ADVERTISEMENT

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 »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.