>>> num_list = list(range(5))
>>> print(num_list)
[0, 1, 2, 3, 4]
slicing will return all elements except element of index 0.
In delete_head()
function, x
will be reference for a list.
x[1:]
will return [1,2,3,4]
and this value will be assign to x
>>> def delete_head(x):
x = x[1:]
>>> delete_head(num_list)
But function is not working
>>> print(num_list)
[0, 1, 2, 3, 4]
But, even I don't use return
statement this function is working:
>>> def d(u):
del u[0]
>>> r = [1,2,3]
>>> d(r)
>>> print(r)
[2, 3]