[Tutor] How to use function with default values ?

2016-08-07 Thread rishabh mittal
Hi I am new to python and come from C language background. I couldn't able to understand this >>> def f(a, L=[]): ... L.append(a) ... return L ... >>> print(f(1)) [1] >>> print(f(2)) [1, 2] >>> print(f(3)) [1, 2, 3] >>> def f(a, L=10): ... L=10+a ... return L ... >

Re: [Tutor] How to use function with default values ?

2016-08-07 Thread Alan Gauld via Tutor
On 07/08/16 04:22, rishabh mittal wrote: > I am new to python and come from C language background. I couldn't able to > understand this > > >>> def f(a, L=[]): > ... L.append(a) > ... return L > ... > print(f(1)) > [1] > print(f(2)) > [1, 2] def f(a, L=10): > ... L=

Re: [Tutor] How to use function with default values ?

2016-08-07 Thread cs
On 07Aug2016 09:19, Alan Gauld wrote: On 07/08/16 04:22, rishabh mittal wrote: I am new to python and come from C language background. I couldn't able to understand this >>> def f(a, L=[]): ... L.append(a) ... return L print(f(1)) [1] print(f(2)) [1, 2] [...] In the first example