【发布时间】:2018-11-05 04:40:16
【问题描述】:
我测试了以下代码:
In [266]: def foo():
...: print("yes")
...:
In [267]: def bar():
...: return foo()
...:
In [268]: bar()
yes
In [269]: x = bar()
yes
我对结果很不解,它充当
In [274]: def foo():
...: return print("yes %.1f" %12.333)
...:
...:
In [275]: foo()
yes 12.3
我该如何理解?很像 shell 脚本 shell 的命令替换 echo $(ls)
【问题讨论】:
-
你调用了
bar(),它调用了foo(),它打印(不是返回,而是打印)“是”。有什么困惑? -
好像没试过
x = bar(); print(x)
标签: python