What I want to do is to create like 10 (or more than 10) variables each containing an int in the name, like M1, M2, M3, M4, M5, M6, M7, M8, M9, M10
Is there any method I can use in Python to iterate over the int contained in the variable name so that I don't have to call each variable when I want to apply the same function to each of them?
Asked
Active
Viewed 1,961 times
0

Mia.M
- 97
- 1
- 1
- 8
-
1don't create such variables in the first place! Use a list. – Jean-François Fabre Feb 01 '17 at 20:41
-
3That is what a *container* is for! E.g. a list, dictionary, set, tuple etc... – juanpa.arrivillaga Feb 01 '17 at 20:42
-
2Maybe you need a so-called "array"? :) M[0], M[1], etc. – friol Feb 01 '17 at 20:44