This is a good example of “Just because you can, doesn’t mean you should.” It is better to reserve SearchEngineEntry.secure_prefix
for only those times when you need to access a variable for the class itself from outside of any instances of the class.
Using self.secure_prefix
is more concise and it will reflect any changes to SearchEngineEntry.secure_prefix
so long as it isn’t overridden by an instance variable of the same name.
codecademy = SearchEngineEntry("www.codecademy.com")
# Change class variable
SearchEngineEntry.secure_prefix = "htps://"
print(codecademy.secure_prefix) # prints htps://
print(SearchEngineEntry.secure_prefix) # prints htps://
# Change it back
SearchEngineEntry.secure_prefix = "https://"
print(codecademy.secure_prefix) # prints https://
print(SearchEngineEntry.secure_prefix) # prints https://
If for some reason, you decided to change it for one instance only:
codecademy.secure_prefix = "httppss://"
print(codecademy.secure_prefix) # prints httppss://
print(SearchEngineEntry.secure_prefix) # prints https://
…then a call to self.secure_prefix
from the codecademy
instance would return the new instance variable instead of the class variable (which is, presumably, what you want if you made that change).