Types and classes in Python

后端 未结 3 564
离开以前
离开以前 2021-02-05 08:36

I\'m a bit confused about types and classes in Python. For e.g. the following REPL conversation confuses me:

>>> class A: pass
... 
>>> a = A()         


        
3条回答
  •  无人及你
    2021-02-05 09:02

    It's "Hystorical reasons". Or possible "Histerical". It's all fixed in Python 3:

    >>> class A: pass
    ... 
    >>> a = A()
    >>> type(a)
    
    >>> a.__class__
    
    >>> type([])
    
    >>> [].__class__
    
    >>> type(list)
    
    >>> list.__class__
    
    >>> type(A)
    
    >>> A.__class__
    
    >>> class B(object): pass
    ... 
    >>> type(B)
    
    >>> b = B()
    >>> type(b)
    
    

提交回复
热议问题