-3

I'm creating new variables for classes, can I do something like this?

for i in range(8): s{i} = card(i, "hearth") #card is class

Or is there some alternative? It would be very helpful if I could do it

I want this output

s0 = card(O, "hearth") s1 = card(1, "hearth") #etc..

2 Answers2

1

Make a list:

s = [card(i, "hearth") for i in range(8)]

Now you have s[0], s[1], etc.

Samwise
  • 68,105
  • 3
  • 30
  • 44
0

You can't dynamically name variables in a loop. I would add them to a list instead:

card_list = [card(i, "hearth") for i in range(8)]

So you can then access them with the index.

Philip09
  • 85
  • 9