执行功能后,Python脚本返回意外的“无” [重复]

执行功能后,Python脚本返回意外的“无” [重复],第1张

执行功能后,Python脚本返回意外的“无” [重复]

在python中,函数的默认返回值为

None

>>> def func():pass>>> print func()     #print or print() prints the return ValueNone>>> func()#remove print and the returned value is not printed. >>>

因此,只需使用:

letter_grade(score) #remove the print

另一种选择是将所有打印内容替换

return

def letter_grade(score):    if 90 <= score <= 100:        return "A"    elif 80 <= score <= 89:        return "B"    elif 70 <= score <= 79:        return  "C"    elif 60 <= score <= 69:        return "D"    elif score < 60:        return "F"    else:        #This is returned if all other conditions aren't satisfied        return "Invalid Marks"

现在使用

print()

>>> print(letter_grade(91))A>>> print(letter_grade(45))F>>> print(letter_grade(75))C>>> print letter_grade(1000)Invalid Marks


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5662068.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存