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)**
Asked By: Shirin Ab

||

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.

Answered By: Jörg W Mittag

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.

Answered By: Alvaro Artano

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"

Answered By: rahi
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.