Everything is an object in python - object class and type class

Chris Angelico rosuav at gmail.com
Wed Jun 3 08:19:04 EDT 2015


On Wed, Jun 3, 2015 at 9:08 PM, BartC <bc at freeuk.com> wrote:
> On 03/06/2015 11:38, Chris Angelico wrote:
>>
>> On Wed, Jun 3, 2015 at 8:20 PM, BartC <bc at freeuk.com> wrote:
>>>
>>> I have a lot of trouble with this stuff too, as my ideas are decidedly
>>> old-fashioned. (Also I'm developing a language with some OO aspects
>>> without
>>> ever having used OO!)
>>>
>>> But, it is mostly just jargon. If you go back to using 'variable' and
>>> 'type', then it becomes a bit easier:
>>>
>>> * A variable is an instance of some type.
>>>
>>> And, that's pretty much it!
>>
>>
>> If I have a list called "stuff" with three elements in it, is
>> "stuff[1]" a variable? What if I return that list from a function
>> called get_stuff()? Is get_stuff()[1] a variable? Because in Python,
>> get_stuff()[1] is certainly going to be an object.
>
>
> Come on, we're trying to keep this simple.
>
> To 'variable' and 'type', you might need to add 'value' to make it more
> complete. An old-fashioned program will be moving values around and
> constructing new ones. Some of them will be loaded from variables, and some
> might end up being stored in variables.
>
> (With the obligatory twist in Python that variable names are not directly
> attached to their values, but via a 'string'. I can introduce a new term for
> what /is/ actually stored /with/ the variable, as it's got to be something
> unless Python works by magic, but I don't want to do that.)
>
> You might call such a value an 'object'. The trouble is, Python also uses
> 'object' to mean the base class of all classes. And it seems to use it in a
> more abstract sense as well to mean pretty much everything. While other
> languages, such as C, use object in yet another way.
>
> Which is where the term breaks down as it no longer helps in understanding.
> It's become meaningless.

Right. My point is that it starts out meaningless, because "variable"
doesn't help with anything. "Value" might help, in which case what
you're saying is that every value in Python is an object (in contrast
to Java, where some aren't). But not all objects are referenced by
names, so "variable" isn't very helpful here.

ChrisA



More information about the Python-list mailing list