Reputation: 2481
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
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
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