Newbie References Question
Padraig Brady
Padraig at Linux.ie
Wed Sep 25 10:46:55 EDT 2002
Guy Rabiller wrote:
> Hi,
>
> let say I have:
> i1 = 1
> i2 = 2
> and
> p = [i1,i2]
>
> How can I have:
> p=[*i1,*i2]
> rather than
> p=[**i1,**i2] as it is curently ?
>
> ( Sorry for this nasty hybrid syntax )
I know what you mean, and being a newbie myself
I thought it would do what you want by default?
If you wrap them in lists then it does as you want:
i1=[1]
i2=[2]
p=[i1,i2]
i1[0]="one"
>>> p
[['one'], [2]]
But I'm confused also as to why this doesn't happen
by default for base types? I suppose when you do:
i1=4 you're creating a new object for the i1 name
to reference, so the p[0] name keeps the reference
to the old object. Hmm I'm confused...
> Textualy, how if I want that p[0] refere to the 'i1' container, and not to
> the refererence it contains ?
>
> What I want is that if now I set:
> i1 = 4
> that automaticaly:
> p -> [4,2]
> and not keeping [1,2]
>
> Thanks in advance.
More information about the Python-list
mailing list