First page Back Continue Last page Overview Graphics

Passing the Copy of a List

>>> def s(s_list):

... s_list += [47,11]

... print(s_list)

...

>>> fib = [0,1,1,2,3,5,8]

>>> s(fib[:])

[0, 1, 1, 2, 3, 5, 8, 47, 11]

>>> fib

[0, 1, 1, 2, 3, 5, 8]

The Slice Operator creates a copy of the list, i.e. fib[:] copies the complete list. This copy is passed on to the function with s(fib).