what is the output of this python code? I got confused
Question:
It shows error but many say the output is " Learn PY 23 "
how is that possible?!
**def m(name,age=20)
print(name,age)
m("learnPY",23)**
Answers:
The code is not syntactically legal Python code.
Hence, the question "what is the output of this Python code" is non-sensical, because it isn’t Python code.
Yes, it is. The thing is that the code is wrong formatted.
def m(name,age=20):
print(name,age)
m("learnPY",23)
If you run it correctly, it will work. This is because you’re calling the function passing two arguments that will be printed.
By considering your code as below(removed **)
def m(name,age=20)
print(name,age)
m("learnPY",23)
In function m argument age is given default value, which is applied only if you don’t pass 2nd argument while calling function.
In your code you have it with 23 so,
the output will be "LearnPY 23"
If you call m("learnPY")
then
the output will be "LearnPY 20"
It shows error but many say the output is " Learn PY 23 "
how is that possible?!
**def m(name,age=20)
print(name,age)
m("learnPY",23)**
The code is not syntactically legal Python code.
Hence, the question "what is the output of this Python code" is non-sensical, because it isn’t Python code.
Yes, it is. The thing is that the code is wrong formatted.
def m(name,age=20):
print(name,age)
m("learnPY",23)
If you run it correctly, it will work. This is because you’re calling the function passing two arguments that will be printed.
By considering your code as below(removed **)
def m(name,age=20)
print(name,age)
m("learnPY",23)
In function m argument age is given default value, which is applied only if you don’t pass 2nd argument while calling function.
In your code you have it with 23 so,
the output will be "LearnPY 23"
If you call m("learnPY")
then
the output will be "LearnPY 20"