为什么我的函数返回数据类型无?:Python 数据类型无 [英] why does my function is returning data type None??: Python datatype None
本文介绍了为什么我的函数返回数据类型无?:Python 数据类型无的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我打印绝对数的python代码.我的函数返回类型 None
.我没有明白我做错了什么.请帮我.
This is my python code for printing an absolute number. My function is returning type None
. I am not getting what I have done wrong. Please help me.
def n(num):
if num<0:
return (num*-1)
no = input("Enter a number: ")
print "Absolute Value is: "
print n(no)
推荐答案
def n(num):
if num<0:
return (num*-1)
else:
return num
no = input("Enter a number: ")
print "Absolute Value is: "
print n(no)
编写 else 语句将返回 num >= 0
writing an else statement will return num >= 0
谢谢:)
这篇关于为什么我的函数返回数据类型无?:Python 数据类型无的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文