0% found this document useful (0 votes)
2 views2 pages

Understanding Python Functions Types

Functions in Python are reusable code blocks that enhance modularity and maintainability. There are two main types: built-in functions, which are pre-defined, and user-defined functions, which are created by programmers. Additionally, normal functions can span multiple lines and require explicit return statements, while lambda functions are anonymous, single-line, and have implicit returns.

Uploaded by

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

Understanding Python Functions Types

Functions in Python are reusable code blocks that enhance modularity and maintainability. There are two main types: built-in functions, which are pre-defined, and user-defined functions, which are created by programmers. Additionally, normal functions can span multiple lines and require explicit return statements, while lambda functions are anonymous, single-line, and have implicit returns.

Uploaded by

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

Functions

A function is a block of reusable code that performs a specific


task. Functions make programs modular, reusable, and easier to
maintain.

Types of Functions

A. Built-in Functions

These are pre-defined in Python.


Examples:
print(len("Hello")) # 5
print(max([1, 2, 3])) # 3
print(type(10)) # <class 'int'>

B. User-defined Functions

Functions created by the programmer.

def greet(name):

return f"Hello, {name}!"

print(greet("Adi")) # Output: Hello, Adi!


Aspect Normal Function Lambda Function

Name Defined using def, has a Anonymous, no explicit


name name

Lines of Can span multiple lines Single-line only


Code

Return Requires return explicitly Implicit return


Statement

Use Case For complex, reusable For short, one-time use


logic

Example def square(x): return x*x lambda x: x*x

You might also like