From: Peng Yu on
pydoc xrange says:

Help on class xrange in module __builtin__:

class xrange(object)

python_2.6.5_library.pdf says:

Objects of type xrange are similar to buffers

Are type and class synonyms? It seems that they are at least according
to some webpages that I read. But I'm not completely sure. Could you
let me know in case my impress is wrong?

--
Regards,
Peng
From: Thomas Jollans on
On 06/22/2010 12:11 AM, Peng Yu wrote:
> pydoc xrange says:
>
> Help on class xrange in module __builtin__:
>
> class xrange(object)
>
> python_2.6.5_library.pdf says:
>
> Objects of type xrange are similar to buffers
>
> Are type and class synonyms? It seems that they are at least according
> to some webpages that I read. But I'm not completely sure. Could you
> let me know in case my impress is wrong?
>

They're the same. *

-- Thomas

* In versions prior to 3.0, this is not 100% true. In versions prior to
2.0, this is not true. **

** Python 2.x distinguishes between "old-style" and "new-style" classes.
New-style classes (those which subclass object) are types. The others
are a bit different, and exist only for backwards compatibility. Don't
use them.
From: Stephen Hansen on
On 6/21/10 3:11 PM, Peng Yu wrote:
> Are type and class synonyms? It seems that they are at least according
> to some webpages that I read. But I'm not completely sure. Could you
> let me know in case my impress is wrong?

Once upon a time, a type was something that was only built-in, provided
by Python, whereas a class was a user-created kind of object that other
objects could inherit from. You couldn't inherit from a type -- only a
class. That's why there were UserDict implementations, and such.

But that's not the case anymore. IIUC, a new-style class is for all
intents and purposes a user-defined type, and the two serve the same
function and are essentially the same.

An old-style class (a class which does not ultimately inherit from
'object') is a bit of a different beast with some different semantics
and exists just for backwards compatibility, I think. The unification of
classes and types occurred in Python 2.2 with PEP252 and PEP253.

There may be some very narrow little cracks where something is slightly
different between types and new-style classes, but I've never run into
it -- except that many types are fundamentally immutable(i.e., ints,
strings), and its awful hard to make an immutable class.

--

Stephen Hansen
... Also: Ixokai
... Mail: me+list/python (AT) ixokai (DOT) io
... Blog: http://meh.ixokai.io/

From: Terry Reedy on
On 6/21/2010 6:11 PM, Peng Yu wrote:
> pydoc xrange says:
>
> Help on class xrange in module __builtin__:
>
> class xrange(object)
>
> python_2.6.5_library.pdf says:
>
> Objects of type xrange are similar to buffers
>
> Are type and class synonyms? It seems that they are at least according
> to some webpages that I read. But I'm not completely sure. Could you
> let me know in case my impress is wrong?

Additional answer:
'type' is the name of the built-in (meta)class that reveals the class of
existing objects (one argument) and creates new classes (three arguments
of the proper class/type ;-).


--
Terry Jan Reedy