I've created a class called Colors()
that has some lists defined in it. I have a method in it called set_alpha()
that has to append the index 3 of the list with the parameter provided.
Here's the block of code:
class Colors():
self.red = (255, 0, 0)
self.blue = (0, 0, 255)
self.green = (0, 255, 0)
def set_alpha(self, alpha):
self[3] = alpha
I knew this would be wrong before I even typed it because I do not understand the
self
thing well. It gives an error saying self is not defined. What I want the result of my class is something like this -
When I do-
Colors.red.set_alpha(128)
I want red to become-
red = (255, 0, 0, 128)
Please explain
EDIT: How do I solve my problem now? How do I use the method set_alpha()
on a variable in the class?