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?
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
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.