Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
160 views
in Technique[技术] by (71.8m points)

Python : terminology 'class' VS '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 ?
  • ... ?
question from:https://stackoverflow.com/questions/4162578/python-terminology-class-vs-type

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It is more or less historical: they used to be different a long time ago, which has no practical implications anymore.

Edit: 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...