Python Forum

Full Version: Operations on indexed variables in loop
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,
Beginner in Python and having spent about 4 hours in this very simple operation, I now rely on your expertise. I'm used to Javascript and in JS you can when you have sets of variables defined (say they're array or matrices), create a loop on those variables indexes to create new ones.
The input variables are defined such as v1, v2, v3, ..., v10 and I want to create new variables such as v11, v12, ..., v20; using the numbers in the name of the variables in the loop index
in my language it'd be:
for i in range (0,10):
	v[i+10]=v[i]/2
Must precise that I'm using Python code into an embedded software so it knows what are the v1, v2, etc...
Any idea what's wrong in here?
Many thanks!
(Aug-14-2019, 05:36 AM)Fibulavie Wrote: [ -> ]Any idea what's wrong in here?

All is wrong. You don't need to create a lot of the same variables, just use lists or dictionaries instead. Every book I read explains lists and dicts on the first ten pages.