这个python代码的输出是什么?我感到困惑[关闭]

xcitsw88  于 2023-04-08  发布在  Python
关注(0)|答案(3)|浏览(98)

**已关闭。**此问题需要debugging details。当前不接受答案。

编辑问题以包括desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将有助于其他人回答问题。
两年前关闭。
Improve this question
它显示错误,但许多人说输出是“学习PY 23”,这怎么可能?!

**def m(name,age=20)
    print(name,age)
m("learnPY",23)**
mcvgt66p

mcvgt66p1#

该代码在语法上不是法律的Python代码。
因此,“这段Python代码的输出是什么”这个问题是没有意义的,因为它不是Python代码。

wnvonmuf

wnvonmuf2#

是的。问题是代码的格式不对。

def m(name,age=20):
  print(name,age)

m("learnPY",23)

如果你正确地运行它,它就会工作。这是因为你调用的函数传递了两个参数,这两个参数将被打印。

thigvfpy

thigvfpy3#

通过考虑您的代码如下(删除**)

def m(name,age=20)
    print(name,age)
m("learnPY",23)

在函数m中,参数age被赋予默认值,只有在调用函数时不传递第二个参数时才应用。
在您的代码中,您使用23,因此输出将为"LearnPY 23"
如果调用m("learnPY"),则输出为"LearnPY 20"

相关问题