Hello there, just checking if I am understanding instance variables so far. I’ve submitted comments describing what I understand is happening as I wrote the code. Does this look correct in terms of my comments? Thank you so much

#Calling a class
class Store:

#Intantiating objects from 'class Store'
alternative_rocks = Store()
isabelles_ices = Store()

#Defining attribute store_name as "Alternative Rocks"
alternative_rocks.store_name = "Alternative Rocks"

#Defining attribute store_name as "Isabelle's Ices"
isabelles_ices.store_name = "Isabelle's Ices"

In both instances you are defining an instance variable. That they have the same name mimics a class instantiation, as though they are defined attributes.

Try this…

>>> alternative_rocks = Store()
>>> isabelles_ices = Store()
>>> alternative_rocks.store_name = "Alternative Rocks"
>>> isabelles_ices.store_name = "Isabelle's Ices"
>>> Store.store_name = "Store Name"
>>> store = Store()
>>> store.store_name
'Store Name'

The latter will be the same for all new instances until they are manually changed (or changed with a setter).

1 Like

Thank you for the clarification! Highly appreciated

1 Like