args_pass_to_func_02.py

#! /usr/bin/python3
# ===================================================================
# Arguments Passed to Function
# ===================================================================
# Python uses a mechanism, which is known as "Call-by-Object",
# sometimes also called "Call by Object Reference" or "Call by
# Sharing". If you pass immutable arguments like integers,
# strings or tuples to a function, the passing acts like
# call-by-value. ... It's different, if we pass mutable arguments.
# ===================================================================

def func(x):
    x[0] = 2
    x.append(4)
    print('func  : x = {}'.format(x))
    return

x = [1,2,3]

print('before: x = {}  {}'.format(x,type(x)))

func(x)

print('after : x = {}  {}'.format(x,type(x)))