On this page
Functions questions in CBSE computer science rarely ask you to write something long. They ask you to trace: what does this call print, what does it return, and which variable changed? This post goes deeper than our Python basics guide for Class 12, with new examples on how arguments travel into a function, what comes back out, and how scope decides which variable you are using. Every output shown was checked by running the code in Python 3.
What does the CBSE syllabus ask about functions?
The CBSE Computer Science curriculum for Class XII (2026-27) lists, in Unit 1: types of function (built-in, functions defined in modules, user-defined), creating user-defined functions, arguments and parameters, default and positional parameters, functions returning values, flow of execution, and global and local scope. Unit 1 carries 40 of the 70 theory marks. The topic is taught in the Class 11 NCERT chapter on functions, which Class 12 revises.
How does the flow of execution work?
Python reads a def statement and stores the function, but runs its body only when the function is called.
def area(length, width=1):
print("computing")
return length * width
print("start")
a = area(5)
b = area(4, 3)
c = area(width=2, length=6)
print(a, b, c)This prints start, then computing three times, then 5 12 12. Nothing inside area runs until the first call.
What is the difference between parameters and arguments?
The parameters are the names in the def line: length and width. The arguments are the values in the call: 5, or 4 and 3.
Positional: area(4, 3) matches by position, so length = 4 and width = 3.
Default: area(5) leaves width out, so it takes its default of 1.
By name: area(width=2, length=6) matches by name, so order does not matter. The Python tutorial calls these keyword arguments.
NCERT states that default parameters must be the trailing ones. Writing def f(a=1, b) gives a SyntaxError: "non-default argument follows default argument".
What does a function return?
def show_total(marks):
print(sum(marks))
r = show_total([40, 35, 25])
print(r)This prints 100 and then None. The function printed a value but returned nothing, and the Python tutorial says that falling off the end of a function returns None. Printing and returning are different: only a returned value can be stored or used in a calculation.
A function can return several values. Python packs them into a tuple:
def min_max(nums):
return min(nums), max(nums)
res = min_max([7, 2, 9])
print(res, type(res).__name__) # (2, 9) tuple
lo, hi = res # lo = 2, hi = 9Can a function change the variable you pass in?
It depends on what you do with it inside.
def add_bonus(scores):
scores.append(5)
def reset(scores):
scores = [0]
s = [10, 20]
add_bonus(s)
print(s) # [10, 20, 5]
reset(s)
print(s) # [10, 20, 5]add_bonus changes the same list object, so s changes. reset only points its local name at a new list, so s is untouched. Numbers and strings cannot be changed in place at all, so a function that does n = n * 2 never changes the caller's variable.
How do local and global scope work?
total = 0
def add(v):
global total
total = total + v
add(5)
add(10)
print(total) # 15Without the global line, the call fails with UnboundLocalError. The Python FAQ explains that when you assign to a variable in a scope, it "becomes local to that scope". Reading a global without assigning to it is fine: a function that only uses rate = 18 to compute cost + cost * rate / 100 returns 236.0 for a cost of 200. The 2026-27 CBSE sample question paper tests exactly this, with y = y + 2 inside a function and no global line, and also asks you to define global and local variables with an example.
What mistakes cost marks?
Confusing print and return, then using the result in a sum and getting a TypeError with None.
A default before a non-default parameter.
Assuming a function changed a number passed to it.
Missing the UnboundLocalError when a function assigns to a global name.
A list as a default value. The tutorial warns that "the default value is evaluated only once", so def add_item(item, basket=[]) returns ['pen'] the first time and ['pen', 'ink'] the second. Use basket=None and create the list inside.
A practice routine for functions
Reading and tracing code is a skill of its own. A study of students from seven countries by Lister and colleagues found that many novices were weak at predicting what a short piece of code does, and argued that this is a prerequisite for writing programs.
Daily for a week: Write two short functions on paper, predict every printed line and the return value, then run them.
Twice a week: Write one function from the suggested practical list, such as a function that returns the maximum, minimum and mean of a list.
Weekly: Do the functions questions from a sample paper under time.
When a concept such as scope still feels slippery, the Fermi Concept Library covers every concept in computing, each with its own lesson. Functions also hold your error handling, which our guide to exception handling in Python covers.
Today, type the add_bonus and reset example, predict both outputs, and run it.



