Python Functions: One Mark Questions, Book Back Answers and Notes
A function is a named block of code that does one job and can be called again and again. This chapter covers user-defined, built-in, lambda and recursive functions, the four kinds of arguments, local and global scope with the global keyword, function composition and the common built-in and math module functions.
Study this chapter
Asked in previous board exams
6 questions from this chapter came in 6 past public exams. Open any of them to see the answer and explanation.
-
March 2026
A function which calls itself is called as:See answer in the solved paper →
-
March 2025
Which of the following keyword is used to exit a function block?See answer in the solved paper →
-
March 2023
A Function which calls itself, is called as :See answer in the solved paper →
-
May 2022
Which function is called as anonymous un-named function ?See answer in the solved paper →
-
Supplementary 2021
Which of the following keyword is used to exit a function block ?See answer in the solved paper →
-
March 2020
Evaluate the following function and write the output.See answer in the solved paper →
x=14.4
print(math.floor(x))
About Python Functions
Medium ~90 min study
If the same ten lines are needed in five places, you should not type them five times. You put them in a function once, give it a name and call it wherever it is needed. Functions make a program shorter, easier to read and easier to correct, because a fix made in one place applies everywhere the function is used.
The chapter moves step by step. First you define a function with def and call it. Then you see how data goes in through arguments: required, keyword, default and variable-length. Once values move in and out of functions, the question of where a variable can be used comes up, which leads to local and global scope. The chapter ends with functions that call other functions (composition) and functions that call themselves (recursion).
Expect questions that ask you to identify the argument type in a call, predict output when a local and a global variable share a name, and trace a recursive function such as factorial. Short questions on built-in functions like abs(), ord(), chr(), round() and math.ceil() are also common.
What you'll learn
- Define a function with def, call it, and use return to send a value back.
- Identify and use required, keyword, default and variable-length arguments.
- Write simple lambda functions and use them with filter() or map().
- Predict output when local and global variables share a name, and use the global keyword correctly.
- Use built-in functions such as abs(), ord(), chr(), round() and the math module functions sqrt(), ceil() and floor().
- Write recursive functions such as factorial with a correct base condition.
Before you start
- Python variables, operators and data types.
- if statements and while and for loops.
- Indentation rules for blocks in Python.
Topics covered in this chapter
Python Functions explained
Writing and Using Functions in Python
Defining and Calling a Function
A function is defined with the def keyword, followed by the function name, parentheses holding any parameters, and a colon. The body is indented below. A return statement sends a value back to the caller; if there is no return, or return has no expression, the function returns None. Calling the function, for example area(5), sends control into the body and brings it back to the calling statement when the body finishes.
Types of Arguments
The textbook lists four kinds. Required arguments are passed in the same order and number as the parameters. Keyword arguments name the parameter in the call, such as show(name="Ravi"), so the order does not matter. Default arguments take a value given in the definition, such as def info(name, salary=3500), when the caller leaves them out. Variable-length arguments use an asterisk, as in def printnos(*nos); all the extra values are collected into a tuple.
Anonymous (lambda) Functions
A lambda function has no name and is created with the lambda keyword instead of def. It can take any number of arguments but contains only one expression, whose value is returned. For example, sum = lambda arg1, arg2: arg1 + arg2 lets you write sum(30, 40) to get 70. Lambda functions are mostly used with filter(), map() and reduce().
Scope of Variables
Scope is the part of the program where a variable can be used. A local variable is created inside a function and exists only while that function runs; it cannot be used outside. A global variable is created outside all functions and can be read anywhere. If a function assigns to a variable of the same name, Python treats it as a new local variable. To change the global one from inside the function, declare it first with global x.
Built-in and Mathematical Functions
Python provides ready-made functions. abs() gives the absolute value, ord() gives the Unicode value of a character, chr() does the reverse, bin() gives the binary form of an integer and type() gives the data type. min(), max(), sum(), round() and pow() are also built in. Functions such as sqrt(), ceil() and floor() belong to the math module, so you must write import math and call math.sqrt(49).
Composition and Recursion
In composition, the value returned by one function is passed straight into another, as in int(input()). A recursive function calls itself to solve a smaller version of the same problem. Factorial is the standard example: fact(n) returns n * fact(n-1), and fact(0) returns 1. That last case is the base condition. Without it the calls never stop, and Python raises a RecursionError once the call depth crosses its limit, which is 1000 by default.
Common mistakes to avoid
- Mixing up parameters and arguments. Parameters are the names in the def line; arguments are the actual values given in the call.
- Assigning to a global variable inside a function without declaring it. Python then treats it as local, and using it before the assignment gives an UnboundLocalError. Write global x at the start of the function.
- Writing greet instead of greet(). Without parentheses the function is not called; you only refer to the function object.
- Writing a recursive function with no base condition, so it keeps calling itself until Python raises a RecursionError.
- Using a reserved keyword such as def, class or return as a function name, which gives a SyntaxError.
Test yourself on these with the practice test, then check the worked reasoning in the solved MCQs.
Frequently asked questions
What is the difference between a parameter and an argument?
A parameter is the variable name written in the function definition, like n in def fact(n). An argument is the actual value sent when the function is called, like 5 in fact(5). When the call happens, the parameter takes the value of the argument.
How do I change a global variable inside a function?
Inside a function, any variable you assign to is local by default. To change the global variable instead, write global followed by its name, for example global c, at the start of the function body. After that, assignments to c update the global variable.
What does a function return if return has no value?
return ends the function and sends control back to the caller. If no expression follows it, or if the function has no return statement at all, the function returns None.
When should I use a lambda function instead of def?
Use lambda for a small operation that fits in one expression, especially when you pass it straight into filter(), map() or reduce(). If the logic needs several statements, loops or a docstring, write a normal function with def.
Why does my recursive function give a RecursionError?
The function keeps calling itself without reaching a stopping case. Either the base condition is missing or the argument never moves towards it, for example calling fact(n) instead of fact(n-1). Python stops the program when the depth crosses its recursion limit, which is 1000 by default.
How do I write a function that accepts any number of arguments?
Put an asterisk before the parameter name, as in def printnos(*nos). All the values passed in the call are collected into a tuple named nos, which you can go through with a for loop.
Last updated 15 September 2026