Python OOP Practice: Objects as State Containers

🔍 Explored something interesting while practicing OOP in Python While working on a simple cricket_player class, I wasn’t trying to learn anything new — just practicing. But during that, I noticed a small but important behavior. 👉 I used: >self.scores = [] to store player scores >add_score(score) to append values >avg_score() to calculate average 💡 What I realized: >The score inside add_score(score) is just a temporary value >But self.scores is the actual storage inside the object >Every time I call add_score(), I’m not passing data around — I’m updating the object’s internal state 📌 That means: The object itself keeps evolving as methods are called #Also noticed: >Even if I pass values as parameters elsewhere, the real source of truth remains self.scores >Functions can take inputs, but what matters is what part of the object they actually use This made me think of objects not just as structures, but as state containers that change over time Just a small observation from practice, but it clarified a lot. #Python #OOP #Programming #LearningByDoing #CodingJourney

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories