Forgive my newbieness - I want to refer to some variables and indirectly alter them. Not sure if this is as easy in Python as it is in C.

Say I have three vars: oats, corn, barley

I add them to a list: myList[{oats}, {peas}, {barley}]

Then I want to past that list around and alter one of those values. That is I want to increment the value of corn:

myList[1] = myList[1] + 1

Is there some means to do that?. Here's my little session trying to figure this out:

>>> oats = 1
>>> peas = 6
>>> myList=[]
>>> myList
[]
>>> myList.append(oats)
>>> myList
[1]
>>> myList.append(peas)
>>> myList
[1, 6]
>>> myList[1]= myList[1]+1
>>> myList
[1, 7]
>>> peas
6
>>>

So I don't seem to change the value of peas as I wished. I'm passing the values of the vars into the list, not the vars themselves, as I would like.

Your guidance appreciated...

Ross.
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to