Python:术语'类'VS'类型' [英] Python : terminology 'class' VS 'type'

查看:174
本文介绍了Python:术语'类'VS'类型'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是一个简单的问题:我应该在什么时候使用'class'这个术语,以及我应该在Python中使用'type'这个术语。

Just a simple question : when should I use the term 'class', and when should I use the term 'type' in Python ?


  • 仅适用于用户定义类型的类,而对于内置类型则为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 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆