निम्नलिखित पायथन कोड का आउटपुट क्या होगा?
What will be the output of the following Python code ?
def say(message, times = 1):
print(message * times)
say('Hello')
say('World', 5)
A)
B)
C)
D)
Explanation:
The correct answer is:
(A) Hello WorldWorldWorldWorldWorld
Explanation:
- In the function
say(message, times=1)
, the default value fortimes
is1
. - When
say('Hello')
is called, it prints the message'Hello'
only once becausetimes
is defaulted to 1. - When
say('World', 5)
is called, the message'World'
is printed 5 times because thetimes
parameter is explicitly set to 5.
Output:
(A) Hello WorldWorldWorldWorldWorld