Creating variables on the fly...
Jhlee at Brooks.com
Mon Apr 3 21:26:11 CEST 2000
I think that this is the place you should use list.
What about this.
r = 0
for something in listVar
r = r + something
I'm still learning python. So please forgive any syntax or naming convetion
>Let's say I have four variables:
>And I have a function that adds these variables together:
> return a+b+c+d
>But now let's say I have twenty variables that I want to add
>This function will no longer work. I would have to rewrite it as
>a+b+c+d+e+f+g+...+(20th letter). Is there a way to
>dynamically create a
>variable name? So that my add function can automatically
>many variable names to create and then add the values together. In
>other words, I'd ideally like something like:
> return a+b+c+...+(letter corresponding to number_of_variables)
>Thanks for your help,
More information about the Python-list