V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
jakeyfly
V2EX  ›  问与答

Python 的类属性会被继承吗

  •  
  •   jakeyfly · Aug 15, 2018 · 1656 views
    This topic created in 2813 days ago, the information mentioned may be changed or developed.

    比如 A()里有 a 类属性 B(A)有 b 类属性 C(B)里有 c 类属性 这样下来 C(B)是否会有 a b c 三个类属性

    3 replies    2018-08-15 08:10:51 +08:00
    wellsc
        1
    wellsc  
       Aug 15, 2018 via iPhone
    whoami9894
        2
    whoami9894  
       Aug 15, 2018 via Android
    ```
    >>> class A():
    ... a=1
    ...
    >>> class B(A):
    ... b=2
    ...
    >>> class C(B):
    ... c=3
    ...
    >>> abc=C()
    >>> abc.a
    1
    >>> abc.b
    2
    >>> abc.c
    3
    ```
    whoami9894
        3
    whoami9894  
       Aug 15, 2018 via Android
    @whoami9894

    ```
    >>> C.a
    1
    >>> C.b
    2
    >>> C.c
    3
    ```
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1858 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 16:18 · PVG 00:18 · LAX 09:18 · JFK 12:18
    ♥ Do have faith in what you're doing.