Python中的函数与过程
>>> def hello():print('HELLO')
>>> temp=hello() #第一行代码
HELLO
>>> print(temp) #第二行代码
None
>>> print(hello()) #第三行代码
HELLO
None
>>> temp #第四行代码
>>>
>>>
小弟的疑惑是由于第一行代码的存在,按理说第二行和第三行代码运行结果应该一样呀,为什么不一样的呢?另外,第四行代码我输入temp,然后点Enter,结果什么也没出现,这是为什么呀?小甲鱼老师在视频里讲的听晕了,在这里,求大神解惑{:5_92:} temp保存的是hello函数的地址,且函数本身并无返回。如果要执行函数,须带上括号,即temp() temp=hello()#得到函数的默认返回值None
print(temp)#打印出None
print(hello()) #打印出函数的返回值None ,“HELLO”是hello()函数打印出来的,而print(hello())只打印函数的返回值None
temp 为None,用print可以打印出来,
#去掉print函数可以就不用讲None打印出来
页:
[1]