jayko03
jayko03

Reputation: 2481

Why does this Python class have different addresses?

I made a simple class:

class Foo:
    pass

then I checked its address with id:

>>> id(Foo)
4299236488

As I was curious, I checked another way:

>>> id(Foo())
4332721208

Why do they have two different addresses?

Upvotes: 0

Views: 46

Answers (2)

SparkAndShine
SparkAndShine

Reputation: 18017

Foo is an object and Foo() is an instance of the object Foo.

>>> type(Foo)
<type 'classobj'>
>>> id(Foo)
140710195094936

>>> type(Foo())
<type 'instance'>
>>> id(Foo())
140710195200224

Upvotes: 1

Tristan
Tristan

Reputation: 2088

You did not check it in another way.

When you call foo you just ask where your class is located.

When you called foo() you created an instance of you class. And then ask where your instance of your class is located.

Upvotes: 0

Related Questions