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.