0% found this document useful (0 votes)
3 views1 page

Python Function

The document explains Python functions, which are reusable code blocks for performing actions. It covers simple functions, functions with parameters, default parameters, and multiple return values. Additionally, it introduces lambda functions as small, anonymous functions used for short tasks.

Uploaded by

revivetech15
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Python Function

The document explains Python functions, which are reusable code blocks for performing actions. It covers simple functions, functions with parameters, default parameters, and multiple return values. Additionally, it introduces lambda functions as small, anonymous functions used for short tasks.

Uploaded by

revivetech15
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

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)

You might also like