More about variables

Matthew Hirsch meh9 at cornell.edu
Thu Apr 6 16:44:54 CEST 2000


Hi All,

Let's say I had something like:

number_of_variables=int(raw_input('Enter number of variables: '))

if number_of_variables==1:
   variable1=[]
elif number_of_variables==2:
   variable1=[]
   variable2=[]
elif number_of_variables==3:
   variable1=[]
   variable2=[]
   variable3=[]
elif number_of_variables==4:
   variable1=[]
   variable2=[]
   variable3=[]
   variable4=[]
elif number_of_variables==5:
   variable1=[]
   variable2=[]
   variable3=[]
   variable4=[]
   variable5=[]
else:
   print 'else'

Is there a more efficient way of doing this? What if I wanted to create 
100 variables (lists).  It doesn't make sense to write an if statement 
for that many conditions.

Thanks for your help,
Matt



More information about the Python-list mailing list