scope of optional arguments

C

cseja

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
 
C

cseja

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top