Functions · Class 11 · CBSE · Science Computer Science

What is the output of the following Python code? x = 10 def change(): global x x = x + 5 return x print(change(), x)

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

hard · MCQ · Q-25AE4A

What is the output of the following Python code? x = 10 def change(): global x x = x + 5 return x print(change(), x)

  1. A.15 10
  2. B.10 15
  3. C.15 15Correct answer
  4. D.Error because x is used inside the function

Solution

The global statement allows the function to modify the global variable x. The function changes x from 10 to 15 and returns 15, so both printed values are 15.

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