Python:术语'类'VS'类型' [英] Python : terminology 'class' VS 'type'
问题描述
只是一个简单的问题:我应该在什么时候使用'class'这个术语,以及我应该在Python中使用'type'这个术语。
Just a simple question : when should I use the term 'class', and when should I use the term 'type' in Python ?
- is 'class' only for user-defined types, and 'type' for built-in types ?
- or now that everything is a type ... should I use always 'type' even for user-defined classes ?
- ... ?
推荐答案
它或多或少是历史的:以前不同,很久以前,这已经没有实际意义了。
It is more or less historical: they used to be different a long time ago, which has no practical implications anymore.
编辑:在使用具体实现时,使用 class
code> type ,当谈到高级数据结构,应用程序等等时。在我的思考中,类型是一个更通用的东西,我不认为每个类作为一个独特的类型。
I use "class
" when referring to concrete implementations and "type
" in a more informal way, when speaking about high level data structures, application arcitecture etc. In my thinking a type is a more general thing, I don't think of every class as a distinct type.
此外,当我使用元类(很少)时,我会说类型。
Also, when I use metaclasses (very rarely) I speak of types.
这篇关于Python:术语'类'VS'类型'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!