Ask Your Question
1

list as a function parameter.

asked 2018-10-14 00:25:51 +0100

damodar gravatar image

updated 2018-10-14 11:45:32 +0100

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-14 01:53:18 +0100 )edit

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

damodar gravatar imagedamodar ( 2018-10-14 08:57:04 +0100 )edit

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

tmonteil gravatar imagetmonteil ( 2018-10-14 11:46:07 +0100 )edit

yes i got my solution. thanq

damodar gravatar imagedamodar ( 2018-10-14 21:29:56 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2018-10-14 12:34:10 +0100

tmonteil gravatar image

updated 2018-10-14 12:34:23 +0100

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-14 00:25:51 +0100

Seen: 537 times

Last updated: Oct 14 '18