蟒蛇书中8.3.3返回字典部分,为什么有input却什么都没有输入就显示下面的结果?看不懂结果是什么意思
因为没有调用a函数。print(a)
,会打印出a的类型。改成print(a())
def a():
dic = {}
while 1:
b = input()
if b == "q":
break
c = input()
if c == "q":
break
dic["bbb"] = b
dic["ccc"] = c
if dic['bbb'] is not None:
break
return dic
print(a())
函数的调用,不加括号是调用的函数本身,也就是函数体(终端显示函数的内存地址),需要函数运行需要在调用的时候加括号
把print(a)改为print(a())