First time here? Check out the FAQ!

Ask Your Question
1

list as a function parameter.

asked 6 years ago

damodar gravatar image

updated 6 years ago

tmonteil gravatar image

.

>>> def fun(x, b= []):
...   b.append(x)
...   print(x,'   ',b)
...
>>> fun(7)
7     [7]
>>> fun([9, 7])
[9, 7]     [7, [9, 7]]
>>> fun([9, 8])
[9, 8]     [7, [9, 7], [9, 8]]
>>>
Preview: (hide)

Comments

1

What is your question ? How is it related to Sage ?

tmonteil gravatar imagetmonteil ( 6 years ago )

I can't able to understand how the outputs work.

damodar gravatar imagedamodar ( 6 years ago )

You need to add some text before the first code block.

tmonteil gravatar imagetmonteil ( 6 years ago )

yes i got my solution. thanq

damodar gravatar imagedamodar ( 6 years ago )

1 Answer

Sort by » oldest newest most voted
2

answered 6 years ago

tmonteil gravatar image

updated 6 years ago

This common "issue" is explained here : https://docs.python-guide.org/writing...

Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 6 years ago

Seen: 554 times

Last updated: Oct 14 '18