Python:术语“类"VS“类型" [英] Python : terminology 'class' VS 'type'
问题描述
只是一个简单的问题:在 Python 中我什么时候应该使用术语类",什么时候应该使用术语类型"?
Just a simple question : when should I use the term 'class', and when should I use the term 'type' in Python ?
- 'class' 仅用于用户定义类型,'type' 用于内置类型?
- 或者现在 一切都是一种类型 ...我应该使用即使对于用户定义的类也总是输入"?
- ... ?
- 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
",而在谈到高级别数据结构、应用程序架构等.在我的想法中,类型是一种更一般的东西,我不认为每个类都是不同的类型.
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屋!