Answer the question
In order to leave comments, you need to log in
How to assign multiple classes the same value to a variable internally?
I want to pull out the value of the color of the shape and use it in the future. The point is not to iterate over if pewka.color == "red" or ladja.color =="red"
but to make it a single variable or class:
if figure == "red": #
else: #
class pewka():
def ___init___(self,x,y,color):
self.x = x
self.y = y
self.color = "red"
class ladja():
def ___init___(self,x,y,color):
self.x = x
self.y = y
self.color = "red"
Answer the question
In order to leave comments, you need to log in
Try to create a figure ancestor class and write general figure properties into it, such as color, state (if necessary) or any that you think of, then you can refer to the variable to read the figure.color ancestor class property
It looks like you don't really understand how classes work.
If you create a self.color attribute, then it is an instance attribute, not a class attribute. You will not be able to access the value of this attribute through the class, this value will be different for each instance.
Everything is very simple
1. Open any python tutorial on the page that tells about OOP in python.
2. Read.
3. Read again carefully.
3.1. Read PEP8
4 as an elective. ?????
5. PROFIT
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question