473,322 Members | 1,408 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

scope of optional arguments

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
Jun 27 '08 #1
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
Jun 27 '08 #2
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.
Jun 27 '08 #3
Thank you very much for your fast and usefull response, Steven. Have a nice
day.
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
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.
14
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...
6
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...
0
MMcCarthy
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
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...
0
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...
1
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)...
1
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
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
0
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...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.