My Life • The Autobiography of a Python Object
A short post showing Python from the eyes of object 0x101dd38c0
And that’s it. I exist.
I have no recollection of anything before this instant. But I’m very aware of what I am now. I’m an object.
This is the line of code that brought me into existence:

My first recollection from a few moments ago was of being inside Team.__new__(). And I felt an affinity with my clan right away. I was a Team instance—an object of type Team.
But then I was whisked from Team.__new__() straight into Team.__init__(). I wasn’t alone. There were two other objects there with me as we all entered .__init__(). But these other objects weren’t from my own clan. One was from the str clan, “The Invincibles”, and the other was a list object, [”Claire”, “Ishaan”, “Margaret”, “Dan”].
This was my initiation ceremony to become a proper member of the Team clan:
Now, I have a closer bond with the other objects that entered .__init__() with me. They’re my data attributes. They go wherever I go.
It’s quite pleasant here. There’s plenty of camaraderie between objects. Some are very much like me, Team objects. Others are somewhat different. But we’re all here to help each other achieve a common goal.
Make sure you don’t miss a thing here at The Python Coding Stack. Join The Club, the exclusive area for paid subscribers for more Python posts, videos, a members’ forum, and more.
…and you’ll be supporting this publication by becoming a member of The Club.
I’m being rather rude. I apologise. I haven’t introduced myself yet.
I’m <__main__.Team object at 0x101dd38c0>. Yes, that’s me. Honest. If you don’t like hexadecimal numbers, you can use the decimal version of my unique identity number:
That number is who I am. It’s the slot in memory I was allocated when I came into existence. It’s the only way you can identify me for as long as I exist. Python gives each one of us objects a unique number so it can distinguish us.
But you can’t call me by that number. That’s not my name, it’s my identity.
You can call me the_invincibles. That’s also easier than using a number, right? Just bear in mind that some other object may steal that name from me later. But for the time being, the_invincibles will do just fine.
And now you have another way to call me if you prefer. I’ll also respond to all_teams[0]. I have two names now!
But if you enquire who I am in the Python program using print(), you won’t get either of those names. Confusing, I know:
Python needs to display me on the screen. It asks me for help to do this.
“Hey, object 0x101dd38c0, do you have a .__str__() special method?”, Python asks me.
“I don’t”, I respond.
“How about .__repr__()? Do you have one of those?”
Yes, as it happens, I do:
So Python asks me to give it whatever this method returns, and it uses it as the return value for print():
Team(
team_name=’The Invincibles’,
members=[’Claire’, ‘Ishaan’, ‘Margaret’, ‘Dan’]
)Python can’t do anything without my help. I feel good about this!
-- --
Python found this code later in the program.
“Hey there again, you”, Python tells me. “I need to ask you something else. Do you have the .__iter__() special method?”
“Yes, I do. What do you need?” I respond.
“Can you give me the iterator from that method, please?”
Here’s the class showing my .__iter__() method, too:
Python now knows what to do to iterate through me:
Claire
Ishaan
Margaret
DanI told you, Python can’t do anything on its own. It needs my help with everything. Good thing I’m here, and I have all the instructions Python needs to deal with me!
-- --
“Psst, it’s me again”, says Python. “Do you know what this .add_member thing is?”
“Yes, yes, it’s one of my attributes, the stuff I carry with me, like everyone else in my Team clan”, I say.
Here’s the code:
-- --
Oh no! I’ve lost my name. But I’m still here, don’t worry. I still exist. Remember that you can still call me using all_teams[0]:
Here’s proof I still exist:
Claire
Ishaan
Margaret
Dan
KeithBut wait a moment. I just caught a glimpse of the next line of code…
“Hey object, can I check something with you, please?” It’s Python again. What does it want this time?
“Do you still have any names left? Any references left?”
I was worried Python would ask me this. There was a time I had two references—two ways you could get to me: the_invincibles and all_teams[0]. But first I lost the name the_invincibles. Now, the object all_teams no longer exists.
I no longer have any references pointing towards me…
Epilogue
Object 0x101dd38c0 would have loved to be here to say goodbye to you in person, but the object is no longer here. Its existence was brief yet fulfilling. Python has no mercy. The moment it realised there was nothing left in the program referring to object 0x101dd38c0, it sharpened the guillotine and…
The irony is that Python still needed help from the object to figure out that there weren’t any references left. Objects keep track themselves of how many references point to them!
It’s what object 0x101dd38c0 had been telling us all along. Python can’t get anything done without the information that objects carry around with them wherever they go!
Photo by Dayan Rodio: https://www.pexels.com/photo/a-man-reading-book-while-sitting-on-a-bed-4132936/
Code in this article uses Python 3.14
The code images used in this article are created using Snappify. [Affiliate link]
Join The Club, the exclusive area for paid subscribers for more Python posts, videos, a members’ forum, and more.
You can also support this publication by making a one-off contribution of any amount you wish.
For more Python resources, you can also visit Real Python—you may even stumble on one of my own articles or courses there!
Also, are you interested in technical writing? You’d like to make your own writing more narrative, more engaging, more memorable? Have a look at Breaking the Rules.
And you can find out more about me at stephengruppetta.com
Further reading related to this article’s topic:
When You No Longer Need That Object • Dealing With Garbage in Python
When Should You Use
.__repr__()vs.__str__()in Python? – Real Python
Appendix: Code Blocks
Code Block #1
the_invincibles = Team(
“The Invincibles”,
[”Claire”, “Ishaan”, “Margaret”, “Dan”],
)
Code Block #2
class Team:
def __init__(self, team_name, members):
self.team_name = team_name
self.members = members
Code Block #3
# ...
print(id(the_invincibles))
# 4326242496
Code Block #4
# ...
all_teams = []
all_teams.append(the_invincibles)
Code Block #5
# ...
print(the_invincibles)
Code Block #6
class Team:
def __init__(self, team_name, members):
self.team_name = team_name
self.members = members
def __repr__(self):
return (f”{type(self).__name__}(”
f”team_name={self.team_name!r}, “
f”members={self.members!r})”)
Code Block #7
# ...
for team_member in the_invincibles:
print(team_member)
Code Block #8
class Team:
def __init__(self, team_name, members):
self.team_name = team_name
self.members = members
def __repr__(self):
return (f”{type(self).__name__}(”
f”team_name={self.team_name!r}, “
f”members={self.members!r})”)
def __iter__(self):
return iter(self.members)
Code Block #9
# ...
the_invincibles.add_member(”Keith”)
Code Block #10
class Team:
def __init__(self, team_name, members):
self.team_name = team_name
self.members = members
def __repr__(self):
return (f”{type(self).__name__}(”
f”team_name={self.team_name!r}, “
f”members={self.members!r})”)
def __iter__(self):
return iter(self.members)
def add_member(self, name):
self.members.append(name)
Code Block #11
# ...
del the_invincibles
Code Block #12
# ...
for team_member in all_teams[0]:
print(team_member)
Code Block #13
# ...
del all_teams
For more Python resources, you can also visit Real Python—you may even stumble on one of my own articles or courses there!
Also, are you interested in technical writing? You’d like to make your own writing more narrative, more engaging, more memorable? Have a look at Breaking the Rules.
And you can find out more about me at stephengruppetta.com















