What is the difference between Type and Class?

前端 未结 20 2304
梦谈多话
梦谈多话 2020-11-28 01:00

What makes a type different from class and vice versa?

(In the general language-agnostic sense)

20条回答
  •  感情败类
    2020-11-28 01:33

    My thoughts are pretty much in line with aku's answer.

    I see classes as a template for building objects, while types are a way to classify those objects, and provide us with an interface to them.

    Python also adds metaclasses, that are just a mechanism to build classes, in the same way as classes build objects (and well, classes and metaclasses are both objects).

    This response to the same question in lamba the ultimate seems to me like a perfect explanation.

提交回复
热议问题