What will be the output of the following code segment? a = 5 def func_1(b=10):…

2025

What will be the output of the following code segment? a = 5 def func_1(b=10): global a a = b - 10 b += a print(a, b) func_1(a)

  1. A.

    0 5

  2. B.

    5 0

  3. C.

    0 -5

  4. D.

    -5 0

Attempted by 253 students.

Show answer & explanation

Correct answer: D

Step 1: The function func_1 is called with a = 5 as the argument for b.

Step 2: Inside the function, the global keyword is used, so the global variable a is updated.

Step 3: a = b - 10 = 5 - 10 = -5.

Step 4: b += a means b = b + a = 5 + (-5) = 0.

Step 5: The print statement outputs a and b, which are -5 and 0.

हिन्दी उत्तर:

चरण 1: func_1 को a = 5 के साथ बुलाया जाता है, जो b के लिए आर्गुमेंट है।

चरण 2: फ़ंक्शन के अंदर, global कीवर्ड का उपयोग किया जाता है, इसलिए ग्लोबल वेरिएबल a को अपडेट किया जाता है।

चरण 3: a = b - 10 = 5 - 10 = -5।

चरण 4: b += a का अर्थ है b = b + a = 5 + (-5) = 0।

चरण 5: print स्टेटमेंट a और b को -5 और 0 के रूप में प्रिंट करता है।

Explore the full course: Bpsc