R
Rishtaara
Computer Science · Class 8

Functions

Learn Functions with notes, examples, and practice questions.

3 sections15–25 min read6 MCQs · 2 examples

Chapter Overview

Functions group reusable code with parameters and return values — reducing duplication and organising programs.

Defining Functions

  • def name(params): body
  • return sends value back
  • Parameters pass data in
  • Call: result = func(arg)

Benefits

  • Reusability — write once, call many times
  • Modularity — break problem into parts
  • Easier testing and debugging

Solved Examples

Step-by-step solutions — read each step before checking the final answer.

Call a function

What is square(4) if def square(n): return n*n?

  1. 1square(4) = 4*4
  2. 2= 16

Answer

16

Loop count

How many times does for i in range(3) run?

  1. 1range(3) → 0, 1, 2
  2. 2Three iterations

Answer

3 times

Key Points to Remember

  • Functions can have default parameters
  • Avoid infinite while loops
  • Use elif for multiple conditions

Exam Tips

  • Write function with return
  • Trace loop iterations
  • Know type conversion

Practice MCQs — Functions

Test your understanding with topic-wise multiple choice questions. Explanations appear after each answer.

Question 1 of 6Score: 0/0

def keyword: