If I call
print walk([1,2,3], [])
print walk([5,6,7])
I get
[1, 2, 3]
[4, 5, 6]
but when I call
print walk([1,2,3])
print walk([5,6,7])
I get
[1, 2, 3]
[1, 2, 3, 4, 5, 6]
at stdout, where
def walk(seq, result = []):
for item in seq:
result.append(item)
return result
Does that mean that the scope of optional arguments is global if they aren't
used and local if they are (or am I missing something here)?
Regards,
CS 3 853 http://www.ferg.org/projects/python_...ontents_item_6
On Mon, May 19, 2008 at 10:30 AM, cseja <p5*****@uni-jena.dewrote:
If I call
print walk([1,2,3], [])
print walk([5,6,7])
I get
[1, 2, 3]
[4, 5, 6]
but when I call
print walk([1,2,3])
print walk([5,6,7])
I get
[1, 2, 3]
[1, 2, 3, 4, 5, 6]
at stdout, where
def walk(seq, result = []):
for item in seq:
result.append(item)
return result
Does that mean that the scope of optional arguments is global if they aren't
used and local if they are (or am I missing something here)?
Regards,
CS
-- http://mail.python.org/mailman/listinfo/python-list
Whoops, I meant to call
print walk([1,2,3], [])
print walk([4,5,6])
and
print walk([1,2,3])
print walk([4,5,6])
with
def walk(seq, result = []):
for item in seq:
result.append(item)
return result
The question is still the same: Why do both calls give different results?
Thank you very much for reading, I'm sorry for the inconvenience.
Thank you very much for your fast and usefull response, Steven. Have a nice
day. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: JT |
last post by:
how can i declare a function that will accept an optional parameter?
something like:
function newFunc(strValue1, strValue2) --where strValue2 is optional.
thanks much.
|
by: cody |
last post by:
I got a similar idea a couple of months ago, but now this one will require
no change to the clr, is relatively easy to implement and would be a great
addition to C# 3.0 :)
so here we go..
To...
|
by: Rob Hoelz |
last post by:
So these two functions are different:
void foo(void);
and
void foo();
because the first one allows no arguments, but the second does. My
question is: In the implementation of the...
|
by: MMcCarthy |
last post by:
We often get questions on this site that refer to the scope of variables and where and how they are declared. This tutorial is intended to cover the basics of variable scope in VBA for MS Access. For...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |