How can you dynamically create variables in Python via a while loop?

Answer

accepted

Unless there is an overwhelming need to create a mess of variable names, I would just use a dictionary, where you can dynamically create the key names and associate a value to each.

a ={}
k =0while k <10:<dynamically create key> 
    key =...<calculate value> 
    value =...
    a[key]= value 
    k +=1

There are also some interesting data structures in the new 'collections' module that might be applicable:

All python Questions

Ask your interview questions on python

Write Your comment or Questions if you want the answers on python from python Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---