Simple newbie question about parameters handling in functions (or am I dump or what?)
From: Niki Iv (niki_iv_at_abv.bg)
Date: 02/10/04
- Next message: Nick Craig-Wood: "Re: Python style advice"
- Previous message: Markus von Ehr: "firewire/IEEE1394 interface for python?"
- Next in thread: Nuff Said: "Re: Simple newbie question about parameters handling in functions (or am I dump or what?)"
- Reply: Nuff Said: "Re: Simple newbie question about parameters handling in functions (or am I dump or what?)"
- Reply: Mike C. Fletcher: "Re: Simple newbie question about parameters handling in functions (or am I dump or what?)"
- Reply: Peter Otten: "Re: Simple newbie question about parameters handling in functions (or am I dump or what?)"
- Reply: anton muhin: "Re: Simple newbie question about parameters handling in functions (or am I dump or what?)"
- Reply: Aahz: "Re: Simple newbie question about parameters handling in functions (or am I dump or what?)"
- Reply: Tim Roberts: "Re: Simple newbie question about parameters handling in functions (or am I dump or what?)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 10 Feb 2004 10:20:11 GMT
I am totaly new to Python, although I have quite strong developer
background. Indeed I am evaluating Python to integrate it (Jython) in
my Java apps...
Well this is my first Python day. I am tampering with functions. I
read that parameters are passed by-value rather than by-reference. So
function can change wathever parameters reffers to. My troube (well my
presonal not understanding comes from this)
Example 1.
def ChangeList(ListToChange):
ListToChange[1] = "Line B"
MyList = ["Line 1","Line 2","Line 3"]
print MyList
ChangleList(MyList)
print MyList
Result is quite understandable (as in Pythin Bible is..)
["Line 1","Line 2","Line 3"]
["Line 1","Line B","Line 3"]
So now function ChangeList.. is
(1) def ChangeList(ListToChange):
(2) ListToChange[1] = "Line B"
(3) ListToChange[2] = "Line C"
(4) ListToChange = ["Line X","Line Y","Line Z"]
Result is the same (as it suppose to be..)
["Line 1","Line 2","Line 3"]
["Line 1","Line B","Line C"]
But now... I am swaping line
(1)def ChangeList(ListToChange):
(2) ListToChange[1] = "Line B"
(3) ListToChange = ["Line X","Line Y","Line Z"]
(4) ListToChange[2] = "Line C"
I have only swapped line 3 and 4.
Result is unexpected
["Line 1","Line 2","Line 3"]
["Line 1","Line B","Line 3"]
The last line in function is to change where ListToChange[2] reffers
to.. but string is the same..
Frankly I was expecting that ListToChange will change it's second
(zero base) element... but it does not.
Why?
Excuse me if the question is stupid.
- Next message: Nick Craig-Wood: "Re: Python style advice"
- Previous message: Markus von Ehr: "firewire/IEEE1394 interface for python?"
- Next in thread: Nuff Said: "Re: Simple newbie question about parameters handling in functions (or am I dump or what?)"
- Reply: Nuff Said: "Re: Simple newbie question about parameters handling in functions (or am I dump or what?)"
- Reply: Mike C. Fletcher: "Re: Simple newbie question about parameters handling in functions (or am I dump or what?)"
- Reply: Peter Otten: "Re: Simple newbie question about parameters handling in functions (or am I dump or what?)"
- Reply: anton muhin: "Re: Simple newbie question about parameters handling in functions (or am I dump or what?)"
- Reply: Aahz: "Re: Simple newbie question about parameters handling in functions (or am I dump or what?)"
- Reply: Tim Roberts: "Re: Simple newbie question about parameters handling in functions (or am I dump or what?)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|