Discuss / Python / 没想着用异常,直接简单判断了一下

没想着用异常,直接简单判断了一下

Topic source

coLBooy

#1 Created at ... [Delete] [Delete and Lock User]
def str2num(s):
    if '.' in s:    #s中有'.',就表示是浮点数。
        return float(s)
    return int(s)

  • 1

Reply