Important Notice:

Functions in Python

Functions in Python

38 views 2 min read

Functions in Python :-

Python Functions (फंक्शन) कोड के ऐसे Reusable Blocks of Code होते हैं, जिनका उपयोग किसी विशेष कार्य (Specific Task) को पूरा करने के लिए किया जाता है। ये Program को छोटे-छोटे भागों (Smaller Sections) में व्यवस्थित (Organize) करने में मदद करते हैं। Function को Call करके आवश्यकता पड़ने पर उसी Code को बार-बार Execute किया जा सकता है।

Python में Function को Define करने के लिए def Keyword का उपयोग किया जाता है। Function को Define करने का Syntax नीचे दिया गया है।

Syntax:-

def function_name(arguments):
# function body
return value
 
 
Example: Without Function and With Function

1. Without Function (Function के बिना) :-

print("Welcome to Python")
print("Welcome to Python")
print("Welcome to Python")

Output:

Welcome to Python
Welcome to Python
Welcome to Python

यहाँ एक ही statement को तीन बार लिखना पड़ा।

2. With Function (Function के साथ) :-

def welcome():
    print("Welcome to Python")

welcome()
welcome()
welcome()

Output:

Welcome to Python
Welcome to Python
Welcome to Python

यहाँ welcome() function को केवल एक बार define किया गया है और तीन बार call किया गया है।
 
IN ENGLISH -
 
Functions in Python :-

Python functions are reusable blocks of code used to perform a specific task. They help organize a program into smaller sections. By calling a function, the same code can be executed repeatedly whenever required.

In Python, the def keyword is used to define a function. The syntax for defining a function is given below.

Syntax:-
def function_name(arguments):

    # function body

    return value


Example: Without Function and With Function

1. Without Function

print("Welcome to Python")

print("Welcome to Python")

print("Welcome to Python")

Output:

Welcome to Python

Welcome to Python

Welcome to Python

Here, the same statement had to be written three times.

2. With Function

def welcome():

    print("Welcome to Python")

welcome()

welcome()

welcome()

Output:

Welcome to Python

Welcome to Python

Welcome to Python

Here, the welcome() function is defined only once and called three times.

Related Notes