Discuss / Python / try捕获异常,用float处理异常

try捕获异常,用float处理异常

Topic source

YOUTH

#1 Created at ... [Delete] [Delete and Lock User]

def str2num(s):

    try:

        return int(s)

    except ValueError as e:

        return float(s)


  • 1

Reply