Everything is an object in python - object class and type class
BartC
bc at freeuk.com
Tue Jun 2 08:49:32 EDT 2015
On 02/06/2015 12:27, Steven D'Aprano wrote:
> "Object" has a general meaning in computer science and programming, it is a
> compound data structure that is explicitly linked to a type which provides
> functionality that operates on that data structure.
>
> In the programming language C, *no* values are objects. C has types (int16,
> uint32, bool, and many more) but no objects.
The C Standard has hundreds of references to 'object'.
C objects are also linked to a type but it doesn't need to be explicit
/in the run-time data/ because it's a static language. The compiler
knows all the types because there are explicit annotations in the source
code.
> In the programming language Java, *some* values are objects, and some values
> are not objects.
>
> In the programming language Python, *all* values are objects, in the general
> sense. That is what we mean by "Everything is an object".
In a dynamically typed language such as Python, you need to be able to
deal with values consistently whatever their type, simply because you
can't tell what the types are from source code. (Not without a lot of
work which Python doesn't attempt, although RPython might do so.) Example:
print (a)
a might be the int 42, or a it might be a million-element list. So both
are wrapped up as 'objects'.
Java is statically typed which makes it possible to treat instance
variables differently without needing to examine their types at runtime.
If you define 'object' in a certain way (eg. as boxed, tagged data),
then it follows that some values don't need to be objects.
--
Bartc
More information about the Python-list
mailing list