ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 14 Aug 2014 06:43:42 -0500Symbolic variables in loopshttp://ask.sagemath.org/question/23776/symbolic-variables-in-loops/Hi,
I got a list of symbolic variables defined like this:
P = list(var('P_%d' % i) for i in range(2*n + 1))
But when I try to manipulate these Variables in a for-loop like:
for k in range(2,n + 2,2):
print(P_k)
I'll get an error "NameError: name 'P_k' is not defined"
I'm guessing there is no k in P_k because its one entity 'P_k' :-D
But I hope it's possible to fix this by using "%" like in the definition above.
Anyone knows how to?
ThanksToreroThu, 14 Aug 2014 06:43:42 -0500http://ask.sagemath.org/question/23776/