我试图写一些代码,但是python没有执行。
def string_length(mystring):
if type(mystring) == int:
return "Sorry, integers don't have length"
elif type(mystring) == float:
return "Sorry, floats don't have length"
else:
return len(mystring)
print(string_length(10.0))
答案 0 :(得分:1)
只需一次使用isinstance:
if isinstance(mystring, str):
return "Sorry"