Inbuilt functions, User-
defined functions and
Lambda functions
]
1. Inbuilt Functions:
• Inbuilt functions, also known as built-in functions, are
pre-defined functions that are part of the programming
language itself.
• Examples of inbuilt functions in Python
include print(), len(), type(), str(), int(), float(), list(), tuple(), di
ct(), and many more.
Function Description
all() Returns True if all elements in an iterable are true
any() Returns True if any one element in an iterable is true
bool() Converts a value to Boolean (True or False)
dict() Creates a dictionary
list() Creates a list
tuple() Creates a tuple
set() Creates a set
help() Opens the help documentation
isinstance() Checks if an object is of a certain type
issubclass() Checks if a class is a subclass of another
map() Applies a function to every item in an iterable
filter() Filters items in an iterable using a function
reduce() (from functools) Reduces a sequence to a single value
reversed() Reverses an iterable
pow() Calculates power (ex: pow(2,3) = 2³ = 8)
open() Opens a file
eval() Evaluates a Python expression from a string
exec() Executes Python code dynamically
bin(), oct(), hex() Converts numbers into binary, octal, and hexadecimal formats
Function Description
all() Returns True if all elements in an iterable are true
any() Returns True if any one element in an iterable is true
bool() Converts a value to Boolean (True or False)
dict() Creates a dictionary
list() Creates a list
tuple() Creates a tuple
set() Creates a set
help() Opens the help documentation
isinstance() Checks if an object is of a certain type
issubclass() Checks if a class is a subclass of another
map() Applies a function to every item in an iterable
filter() Filters items in an iterable using a function
reduce() (from functools) Reduces a sequence to a single value
reversed() Reverses an iterable
pow() Calculates power (ex: pow(2,3) = 2³ = 8)
open() Opens a file
eval() Evaluates a Python expression from a string
exec() Executes Python code dynamically
bin(), oct(), hex() Converts numbers into binary, octal, and hexadecimal formats
2. User-Defined Functions:
• User-defined functions, also known as custom functions,
are created by the programmer to perform specific
tasks.
• User-defined functions are defined using the def keyword
in Python
Types of Users defined functions
1. Parameterized Functions
2. Functions with default
arguments
3. Keyword argument functions
Keyword arguments are a way of passing values to a
function by using the parameter names.
Instead of just giving values in order (like positional
arguments), you specify which value goes to which
parameter.
4. Variable-Length Arguments
You can pass as many arguments as needed — either positional or keyword — without fixing them
in advance.
There are two types:
*args – for non-keyword (positional) variable arguments
**kwargs – keyword (named) variable arguments
for
5. Functions with Return value
A function with a return value is one that sends a result back to the part of the program
where it was called.
This is done using the return statement.
Key Points:
•The return statement ends the function and sends back a value.
•You can return any data type — numbers, strings, lists, even other functions!
•A function can return multiple values (as a tuple).
Lambda functions
• A lambda function is a small, anonymous (nameless) function defined using the lambda
keyword.
• It can have any number of arguments but only one expression.
• It's used when you need a simple function for a short time, often as an argument to another function.
Pass by Value or Pass by
Reference
• Python passes the reference to the object (not a copy).
• But you can't change immutable objects (like integers, strings) inside
the function — it looks like pass-by-value.
• You can change mutable objects (like lists, dictionaries) — it behaves
like pass-by-reference.
EXAMPLES
• "You are managing a college library. A student returns a book late. The
library charges ₹1/day for the first 5 days, ₹2/day for 6–10 days, and
₹5/day after that. Write a Python function to calculate the total fine
and return the amount.
"You're building a student result system for a school. Based on total
marks (out of 100), return the appropriate grade using the following
scale:
• A+ for 90 and above
• A for 80–89
• B for 70–79
• C for 60–69
• D for 50–59
• Fail for below 50"*