Python functions:
A Python function is a block of organized, reusable code that is used to perform a
single, related action.
#Python Functions:Repeated executions
#Simple function
'''def msg():
print("welcome")
msg()
=============
#2Function with parameters:
def add_numbers(a, b):
return a + b
result = add_numbers(10, 20)
print("Sum:", result)
===============================
Function with default parameters
def welc(name="data"):
print("hello,",name)
welc()
welc("analyst")
===================================
Function with multiple return values:
def stats_1(inputdata):
return min(inputdata),max(inputdata),sum(inputdata)/len(inputdata)#Since we
dont have average function in python ,we are using sum and len to find the
average
values=(1,2,3,4)
minimum,maximum,avg=stats_1(values)
print("min:",minimum)
print("max:",maximum)
print("avg:",avg)
=================================================================================
What is a Lambda Function?
A lambda function is a small, anonymous (unnamed) function.
It can take any number of arguments, but only one expression.
It’s often used for short, throwaway functions where defining a full def function
is overkill.
lambda arguments: expression
# Step 1: Define a lambda function to square a number
square = lambda x: x * x
# Step 2: Use the function with an input
result = square(5)
# Step 3: Print the result
print("Square is:", result)