निम्नलिखित प्रोग्राम का आउटपुट क्या है?
What is the output of the following program ?
def myfunc(a):
a=a+2
a=a*2
return a
print myfunc(2)
A)
B)
C)
D)
Explanation:
Let's analyze the given Python code:
def myfunc(a):
a = a + 2
a = a * 2
return a
print(myfunc(2))
Step-by-Step Explanation:
-
Function Definition:
- The function
myfunc(a)
takes one argumenta
. - Inside the function:
- First,
a = a + 2
increasesa
by 2. - Then,
a = a * 2
doubles the new value ofa
.
- First,
- Finally, the function returns the value of
a
.
- The function
-
Function Call:
- The function is called with
a = 2
, so:a = 2 + 2
→a = 4
a = 4 * 2
→a = 8
- The function then returns
8
.
- The function is called with
-
Output:
- The
print(myfunc(2))
will print the returned value, which is8
.
- The
Answer:
(A) 8