zoukankan      html  css  js  c++  java
  • 10.3.4 处理多个异常的except 语句:

    10.3.4 处理多个异常的except 语句:
    
    我们还可以在一个except 子句里处理多个异常,
    except 语句在处理多个异常时要求异常被放在一个元组里:
    
    
    def safe_float(obj):
        try:
            retval = float(obj)
        except (ValueError,TypeError):
            retval = 'argument must be a number or numeric string'
            return retval
    class fun1(object):
        def __init__(self):
            pass
    b=fun1()
    print b
    print type(b)
    a=safe_float(b)
    print a
    
    C:Python27python.exe C:/Users/TLCB/PycharmProjects/untitled/mycompany/ddd/a20.py
    <__main__.fun1 object at 0x022A7310>
    <class '__main__.fun1'>
    argument must be a number or numeric string
    
    
    def safe_float(obj):
        try:
            retval = float(obj)
        except (ValueError,TypeError):
            retval = 'argument must be a number or numeric string'
            return retval
    class fun1(object):
        def __init__(self):
            pass
    b=fun1()
    print b
    print type(b)
    a=safe_float('abc')
    print a
    
    C:Python27python.exe C:/Users/TLCB/PycharmProjects/untitled/mycompany/ddd/a20.py
    <__main__.fun1 object at 0x022A7310>
    <class '__main__.fun1'>
    argument must be a number or numeric string
    

  • 相关阅读:
    Java Concurrency
    Java Annotation,Java注解
    Think in java, notes
    嵌套事务
    java dynamic proxy,动态代理
    埃里克·雷蒙德
    HDU1222 Wolf and Rabbit
    HUT1098 素MM
    HDU1568 Fibonacci
    HDU1501 Zipper DFS+记忆化搜索
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349233.html
Copyright © 2011-2022 走看看