Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #36080
| Date | 2013-01-03 20:21 +0000 |
|---|---|
| From | MRAB <python@mrabarnett.plus.com> |
| Subject | Re: Question on for loop |
| References | <456df1a1-9225-44e7-9aa9-6b6fe3fde4a0@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.57.1357244517.2939.python-list@python.org> (permalink) |
On 2013-01-03 20:04, subhabangalore@gmail.com wrote: > Dear Group, > If I take a list like the following: > > fruits = ['banana', 'apple', 'mango'] > for fruit in fruits: > print 'Current fruit :', fruit > > Now, > if I want variables like var1,var2,var3 be assigned to them, we may take, > var1=banana, > var2=apple, > var3=mango > > but can we do something to assign the variables dynamically I was thinking > of > var_series=['var1','var2','var3'] > for var in var_series: > for fruit in fruits: > print var,fruits > > If any one can kindly suggest. > > Regards, > Subhabrata > > NB: Apology for some alignment mistakes,etc. > Why would you want to do that? Creating names dynamically like that is a bad idea. Just keep them in a list, like they are already.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Question on for loop subhabangalore@gmail.com - 2013-01-03 12:04 -0800
Re: Question on for loop MRAB <python@mrabarnett.plus.com> - 2013-01-03 20:21 +0000
Re: Question on for loop Peter Otten <__peter__@web.de> - 2013-01-03 21:22 +0100
Re: Question on for loop Matt Jones <matt.walker.jones@gmail.com> - 2013-01-03 14:28 -0600
Re: Question on for loop Don Ross <donrosszx@gmail.com> - 2013-01-03 15:22 -0800
Re: Question on for loop alex23 <wuwei23@gmail.com> - 2013-01-03 16:47 -0800
Re: Question on for loop Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-01-04 05:48 +0000
Re: Question on for loop subhabangalore@gmail.com - 2013-01-15 11:30 -0800
Re: Question on for loop Alister <alister.ware@ntlworld.com> - 2013-01-04 10:16 +0000
csiph-web