Py:这个返回值None, 为何?
def calc(money):if money <= 5000:
tax = 0
elif 5000 < money <= 8000:
tax = (money - 5000) *3/100
else:
tax = (money - 8000) *5/100 + 3000 *3/100
if __name__ == "__main__":
print(calc(6666))
run后:
None
Process finished with exit code 0
请问这个返回值,为何算不出来,python 给出了个 None? 我哪里写错了么?请教高手们。
calc木有返回值,所以返回none def calc(money):
if money <= 5000:
tax = 0
elif 5000 < money <= 8000:
tax = (money - 5000) *3/100
else:
tax = (money - 8000) *5/100 + 3000 *3/100
return tax
if __name__ == "__main__":
print(calc(6666)) 函数没有设置return,就会返回none,print打印函数calc什么都没有得到,就打印返回的none了。
也许平时直接在函数里面带上了print所以没有注意到返回值的作用,但在这个例子中,你在外部print方法打印,函数的return作用就表现出来了。 wp231957 发表于 2021-5-31 12:06
calc木有返回值,所以返回none
感谢指正~ wp231957 发表于 2021-5-31 12:08
def calc(money):
if money
多谢您的指点
页:
[1]