I've seen a few snippets of code in different languages where a class has a class variable, but then in the same class, there's also an instance variable of the same name. I'm trying to understand why we would do this? What would be the benefits of doing something like this:
class Paint:
colour = 'red'
def __init__(self, name, counter):
self.id = name
self.colour = colour
This is in Python and just an example. I'm trying to understand the benefits, and why someone would do this, in any programming language, but particularly C++, ruby, and python.
__init__is conditional somehow, the class attribute would act as a default value.@@double at sigil. Also, there are no instance variables in your code, instance variables start with a@at sigil.@@. The variables in your code are local variables. At least, they would be in Ruby, which is what your question is tagged with.