🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Python Functions: all 15 questions

Quiz: Python Functions · Question 12 of 15

What does this print? (code)

What does this print?

count = 0
def add():
    global count
    count += 1
add()
add()
print(count)
  1. A.0
  2. B.1
  3. C.2
  4. D.UnboundLocalError
Answer & explanation

Correct answer: 2

global count lets the function change the global variable, and it is called twice.

Can you get the rest right without peeking?

Take the timed Quiz: Python Functions quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →