Skip to main content
 首页 » 编程设计

python之这到底有什么问题

2025年05月04日12dyllove98

我正在阅读一个关于定义函数的教程,其中包含一个创建新行的示例,您必须编写的代码是这样的:

def new_line(): 
    print 
 
def three_lines(): 
    new_line() 
    new_line() 
    new_line() 
 
def nine_lines(): 
    three_lines() 
    three_lines() 
    three_lines() 
 
print "hello world" 
 
print nine_lines() 
 
print "goodbye" 

谁能解释为什么它在“再见”之前包含“无”?

请您参考如下方法:

print nine_lines() 

您正在打印调用 nine_lines() 函数的结果。由于该函数不会显式返回值(使用return 语句,如果您还没有看到它,那么您很快就会看到),Python 返回特殊值无。

要解决这个问题,只需将该行更改为

nine_lines()