School Revise · Class 11 Computer Science · Chapter 7
Code 083, Class 11. A function is a named block of code we can reuse. Here we define our own functions, pass values to them, return results and understand scope.
|
|
A function is a named block of code that does one job. We call it by its name whenever we need it, which saves repeating code and keeps programs tidy.
We define a function with def, give it parameters in brackets, and use return to send a result back. We call it by writing its name with values (arguments).
|
def add(a, b): return a + b print(add(5, 3)) Output: 8 |
Positional arguments are matched by order. A default argument has a value ready, so it may be left out when calling.
A variable made inside a function is local and cannot be seen outside. A variable outside is global. Python has built-in functions like print() and len(), and the ones we write are user-defined.
Build a small function, set its arguments, and see the value it returns. The interactive opens right here in the lesson.
Write and run real Python right here in the lesson, then work through the practice problems with answers.
Type each one into the code lab above, then open the card to see the worked solution and its output.
SOLUTION
OUTPUT
SOLUTION
OUTPUT
SOLUTION
OUTPUT
SOLUTION
OUTPUT
SOLUTION
OUTPUT
SOLUTION
OUTPUT
SOLUTION
OUTPUT
SOLUTION
OUTPUT
SOLUTION
OUTPUT
SOLUTION
OUTPUT
def.
return.
local, and cannot be seen outside.
built-in functions.
|
A function is a named, reusable block of code. We define it with def, pass values as arguments (matched by position or given as defaults), and use return to send a result back. Variables made inside are local; those outside are global. print() and len() are built-in functions, and the ones we write are user-defined. |
| Open the Virtual Lab |
These free Class 11 Computer Science notes explain functions, defining and calling, parameters and arguments, return values, default arguments, local and global scope with worked Python programs and practice, for CBSE students across India and the Gulf including the UAE, Saudi Arabia, Qatar, Oman, Kuwait and Bahrain.
© 2026 School Revise. All rights reserved. Original content aligned to the CBSE and NCERT Class 11 Computer Science syllabus. Unauthorised copying is not permitted.