|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
下面两个代码唯一的区别在于最后的print, 为什么加了print,最后返回的结果会多一行Non呢?思考了半天,都不能得解啊啊啊
大家帮忙看一下,谢谢啦!!!
代码 (1) ++++++++++++++++++++++++++++++++++
name = input('请输入一个名字:')
def hellocounter(name):
count = 0
def counter():
nonlocal count
count+=1
print('Hello,'+name+','+str(count)+'access!')
return counter()
hellocounter(name)
返回值:
请输入一个名字:小甲鱼
Hello,小甲鱼,1access!
代码 (2) ++++++++++++++++++++++++++++++++++
name = input('请输入一个名字:')
def hellocounter(name):
count = 0
def counter():
nonlocal count
count+=1
print('Hello,'+name+','+str(count)+'access!')
return counter()
print(hellocounter(name))
返回值:
请输入一个名字:小甲鱼
Hello,小甲鱼,1access!
None
本帖最后由 塔利班 于 2018-1-22 23:19 编辑
你自己试试print(print('我擦'))
就知道了
print()函数本身没有返回值
你再用print一遍,python表示懵逼,返回个NONE,
表示没有可显示的
|
|