• python 笔记6


    类对象与继承

    class A():
    x =6
    x1=["221"]
    print("123")
    def add(self,x,y):

    return x+y
    def __init__(self,m,n):
    self.m =m
    self.n = n
    def fun(self,y):
    print(y,self.x,self.m)
    class B(A):
    print("456")
    x=63
    def __init__(self,m,n,g):
    super().__init__(m,n)
    self.g=g
    def add(self,m,n,g):
    return m+n+g

    a =B(9,52,6)
    a.x =111
    a.x1.append("3")
    l =a.add(1,2,3)
    t =a.x
    k=a.m

    print(l,t,a.m ,a.x1 is A.x1,a.x1,a.n,a.g)

    返回值:

    123
    456
    6 111 9 True ['221', '3'] 52 6

    Process finished with exit code 0

     异常与捕获

    def f(a):
    print(a+1)

    try:
    f(b)
    except TypeError:
    print("类型错误")
    except NameError as e:
    print("名称错误",e)
    except Exception:
    print("未知错误")
    else:
    print("正常")
    finally:
    print("all pass")


    返回值

    名称错误 name 'b' is not defined
    all pass

  • 相关阅读:
    HDU 5650 异或
    HDU 5646
    HDU 5645
    P2075 [NOIP2012T5]借教室 区间更新+二分查找
    HDU 5641
    读写分离
    linux执行cmd之一
    html2image
    挂载引起的权限问题
    如何防止sql注入
  • 原文地址:https://www.cnblogs.com/lionmxs/p/16074198.html
Copyright © 2020-2023  润新知