J
Jayden
In learning Python, I found there are two types of classes? Which one are widely used in new Python code? Is the new-style much better than old-style? Thanks!!
In learning Python, I found there are two types of classes? Which one are widely used in new Python code? Is the new-style much better than old-style? Thanks!!
In learning Python, I found there are two types of classes? Which one are widely used in new Python code? Is the new-style much better than old-style? Thanks!!
In learning Python, I found there are two types of classes? Which one
are widely used in new Python code?
Is the new-style much better than old-style?
In learning Python, I found there are two types of classes? Which one are widely used in new Python code? Is the new-style much better than old-style? Thanks!!
New-style classes.
Yes.
Always use new-style classes, unless you have some specific reason for
needing old-style ("classic") classes.
Advantages of new-style classes:
1) They are the future. In Python 3, all classes are "new-style" and
classic classes are gone.
2) Multiple inheritance works correctly. Multiple inheritance for classic
classes is buggy.
3) New-style classes support awesome features like super(), properties,
descriptors, and __getattribute__. Old-style do not.
The main disadvantage is that automatic delegation is a pain to do
correctly in new-style classes, but trivially simple in classic classes.
Still, all things considered, it's a good trade.
In learning Python, I found there are two types of classes? Which one are widely used in new Python code? Is the new-style much better than old-style? Thanks!!
Jayden said:In learning Python, I found there are two types of classes? Which one are
widely used in new Python code? Is the new-style much better than old-style?
Thanks!!
In learning Python, I found there are two types of classes? Which one arewidely used in new Python code? Is the new-style much better than old-style? Thanks!!
The interesting point or my question.
Why a Python beginner arrives here and should ask about this?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.