Functions · Class 11 · CBSE · Science Computer Science

What is the output of the following Python code? def add(a, b=2): return a + b print(add(3))

Practice question from Functions (Class 11 · CBSE · Science Computer Science), with the correct answer and a step-by-step solution.

easy · MCQ · Q-92F0B2

What is the output of the following Python code? def add(a, b=2): return a + b print(add(3))

  1. A.3
  2. B.5Correct answer
  3. C.6
  4. D.Error because b is not provided

Solution

The parameter b has a default value of 2. Therefore, add(3) returns 3 + 2, which is 5.

More from Functions

All of Functions

Practise more Computer Science

Sign up free for adaptive practice on this chapter, with instant feedback and hints on every question.

Start practising free

Free to start · No credit card needed