看一下
1.代码如下:def hello():
print('hello world')
temp=hello()
'hello world'
temp
无显示
我想知道这两个temp的含义和区别看不懂这两个结果为啥不同 因为第一次 hello() 实例化给 temp 会调用 hello() 函数,把调用后返回的值传给 temp
又因为你这里没有设置return 返回值 所以返回的为 None 即为空
所以你第二次 temp 显示的是空
你可以这样查看下他是什么东东 :
print(type(temp))
Twilight6 发表于 2020-6-4 14:35
因为第一次 hello() 实例化给 temp 会调用 hello() 函数,把调用后返回的值传给 temp
又因为你这里没有 ...
>>> def hello():
print('nihao')
temp=hello()
SyntaxError: unindent does not match any outer indentation level
>>> 还有一个问题,print语句打完以后为什么要空一行才能输temp=hello()啊?不空一行的话就报错但是空了一行就对了这是为什么
波大大12138 发表于 2020-6-4 14:44
>>> def hello():
print('nihao')
temp=hello()
缩进不正确导致报错 ,而且函数内部直接调用本身 叫递归 后期会学习到 {:10_266:}刷个荣誉
页:
[1]