python - Creating an empty list to have data assigned afterwards -


lets want create list of names

listofnames = [] 

then have while loop such as

count = 0 while listofnames[count] < 10:     namelist[count] = raw_input("enter name: ")     count += 1 

python says list index out of range, list index should @ 0, correct?

how add list each time while loop ran? i'm assuming wrong list assignment.

an empty list doesn't have index yet, it's empty list! if want fill it, have :

while count < 10:     namelist.append(raw_input("enter name: "))     count += 1 

this way, condition evaluated , append method, able add new items in list.

there few advanced tricks easily, considering level, think it's better understand code before moving on.


Comments

Popular posts from this blog

SAP Web Service from .NET via WCF -

c# - Getting "Internal .Net Framework Data Provider error 30" error when column has NULL value -

c++ - How to modify context menu of internet explorer using IDocHostUIHandler::ShowContextMenu? -