On 07/03/2015 15:39, elie khairallah wrote:
hello , I would like to know if theres a way to change a variable's name
after every iteration for example I want to make a function that stores a
number in x_1 if i=1 and in x_2 if i=2.
To be more precise:
i=1
def f(n):
        while i<n:
               x_i = i**2  ##this writing is wrong I would like here to have
x_1 or x_2 ...
                                      (depending on i)
         return (x_1,x_2,x_3 .....)

Why bother?  What's wrong with this?

def f(i, n):
    values = []
    for x in range(i, n+1, 1):
        values.append(x**2)
    return values

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to