Ask Your Question
1

list as a function parameter.

asked 2018-10-13 17:25:51 -0500

damodar gravatar image

updated 2018-10-14 04:45:32 -0500

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]]
>>>
edit retag flag offensive close merge delete

Comments

1

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

tmonteil gravatar imagetmonteil ( 2018-10-13 18:53:18 -0500 )edit

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

damodar gravatar imagedamodar ( 2018-10-14 01:57:04 -0500 )edit

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

tmonteil gravatar imagetmonteil ( 2018-10-14 04:46:07 -0500 )edit

yes i got my solution. thanq

damodar gravatar imagedamodar ( 2018-10-14 14:29:56 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2018-10-14 05:34:10 -0500

tmonteil gravatar image

updated 2018-10-14 05:34:23 -0500

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

edit flag offensive delete link more

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: 2018-10-13 17:25:51 -0500

Seen: 95 times

Last updated: Oct 14