<分区>
def white():
print
print ("First line")
white()
print ("Second line")
这是我的第一个脚本。当我按下“F5”键时,结果如下:
First line
Second line
错在哪里?
<分区>
def white():
print
print ("First line")
white()
print ("Second line")
这是我的第一个脚本。当我按下“F5”键时,结果如下:
First line
Second line
错在哪里?
最佳答案
您正在使用 Python 3,其中 print
是一个函数。在 Python 2 中,print
是一个语句,您的代码将按照您的预期运行。
这一行:
print
不调用函数。它只是查找名称 print
。这不会导致在输出设备上放置任何东西。
你大概是想写这样的东西来实际调用函数:
def white():
print()
print ("First line")
white()
print ("Second line")
输出
First line Second line
关于python - 函数不打印预期结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21190071/
相关文章:
Python - 带有 input() 的 If 语句在 def() 函数内部不起作用
python - 如何使用 selenium 向 hideNameInput 发送 key ?
python - 在 Python 3 中将逗号分隔的字符串转换为 Numpy 数组
python - Jupyter notebook 不运行代码。停留在 [*]
javascript - 如何在 JavaScript 中将数组的数组作为行转换为数组的数组作为列?
c++ - 以多态类型作为函数参数的 std::function 的容器
javascript - 如何将一个异步函数的结果使用到另一个异步函数