If I were to have a list aList = ['Apple', 'Banana', 'Cherry', 'Date']
, and I wanted to make each item in the list an object, for example the equivalent of Banana = AClass()
. After doing this, I would be able to create and call self.anything
for each item in the list.
How would I go about doing this?
Here is essentially what I am trying to achieve:
import random
class Fruit:
def __init__(self):
self.tastiness = random.randint(1,10)
fruits = ['Apple', 'Banana', 'Cherry', 'Date']
fruits[1] = Fruit() # Creating a variable from the list
if Banana.tastiness < 5:
print('Not tasty enough')