hai friends
i am 5 days old in learning python programming. I know perl for limited usage. I have a doubt regarding getting input in list during run time. is there any other way in python than typing like ["hi","hello"]. why it is not possible to insert value as we insert values in array (c, perl) like a[0]. it is one way, we can only access list in such way but we cannot insert value like that.

please clear my doubt. thanks in advance

This is possible in python my friend.


# to Add
alist.append("bingo")## to add to the last slot
alist.insert(3, "three")# Insert to where you wantt. eg in C alist[3]="three"


##Out Put
['one', 'foo', 'spam', 'three', 'more', 'spam', 1, 5, 'bingo']

Play around with python list. This is the same as array in C,C++...

hai thanks for your reply
ya i tried that option
but i wanted to know whether is it possible get a run time input and store value in list one by one.

print "enter the number of values that u want to enter"
while (i<no):
         ai[i]= raw_input("enter the ids")

print ai

this ai is not holding all the list i am giving its holding only the last value which i gave. i want to store all the values which i am giving in a orderly way in list.
please clear my doubt.
values = []
for count in range(int(raw_input('Number of inputs'))):
    values.append(raw_input('%i:' % (count+1)))

Edited 5 Years Ago by pyTony: n/a

hai thank you very much. i tried this code its working fine. my doubt is cleared.

This article has been dead for over six months. Start a new discussion instead.