无法执行某些代码

时间:2019-06-20 08:39:14

标签: python-3.7

我试图写一些代码,但是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))

1 个答案:

答案 0 :(得分:1)

只需一次使用isinstance:

if isinstance(mystring, str):
    return "Sorry"