नीचे दिए गए Python कोड का आउटपुट क्या होगा?
What will be the output of the following Python code?
x = 15
def f1(a, b=x):
print(a, b)
f1(4)
A
4 15
B
4 x
C
4
D
Error
Explanation
x = 15
def f1(a, b=x):
print(a, b)
f1(4)
इस कोड में function f1 दो arguments लेता है:
-
a→ required argument -
b→ default argument, जिसकी value हैx, और उस समयx = 15
🔍 क्या होता है:
-
जब function
f1(4)को call किया गया, तो:-
a = 4 -
bको कोई value नहीं दी गई, इसलिए इसका default value (x = 15) इस्तेमाल होगा
-
➡ Output: 4 15
❗ Important Note:
Default arguments को function definition के समय evaluate किया जाता है, call के समय नहीं।
Correct Answer: A) 4 15