List mutability =============== #. Which is the value of list ``a`` after each of these assignment statements ? .. code:: python a = [['a', 1], 3, [4, 5, 'b'], [1, [2, 'c'], 9]] a[0] = 5.7 a[-1] = 'hello' a[1] = ['X', 1, 2.5] a[0:2] = [0, 1] a[2:4] = [] a[0:1] = [2, 3, 4, 5] a[1:1] = ['x', 'y'] a[-2:] = ['a', 'b', 'c'] a[:-5] = [0, 1, 2] a[15:20] = [5, 6] #. List ``a`` has been defined as follows: .. code:: python a = ['a', 'b', 'c', 'd', 'e', 'f'] write assignment statements to match the following expressions: .. code:: python a == ['a', 'b', 1, 'd', 'e', 'f'] a == ['a', 'b', 'c', 'd', 2, 3] a == ['a', 'e', 'f'] a == ['a', 'b', 'c', 'd', 4, 5, 'e', 'f'] a == [6, 'c', 'd', 'e', 'f'] a == ['a', 'b', 'c', 7] a == ['a', 8, 9, 'f'] a == ['a', 'b', 'c', 'd', 'e', 'f', 10, 11, 12] #. Which is the value of list ``b`` after the execution of each of the following assignment statements ?: .. code:: python b = ['garlic', 'onion', 'parsley'] del b[0] b[0] = 'thyme' b[0] = ['garlic', 'onion', 'rosemary'] b[0:1] =['garlic', 'onion'] b = b + b #. We have written the two following Python functions .. code:: python def list_test1(w): w = [1,1,1,1] w[1] = 5 def list_test2(w): w[1] = 5 w = [1,1,1,1] What will the value of variables k1 and k2 be after executing the following instructions ? .. code:: python >>> k1 = [0,0,0] >>> k2 = [0,0,0] >>> list_test1(k1) >>> list_test2(k2) Give a reasoned answer. You can check the result using the following test file: :download:`mutab.txt ` #. After executing these assignment statements: .. code:: python a = ['a', 5, [], 3.2, [4, 'bc']] b = ['a', 5, [], 3.2, [4, 'bc']] have ``a`` and ``b`` the same value? Are they the same object ? You can check it by using the operators ``==`` and ``is``, respectively. #. After executing these assignment statements: .. code:: python a = ['a', 5, [], 3.2, [4, 'bc']] b = a have ``a`` and ``b`` the same value? Are they the same object ? You can check it by using the operators ``==`` and ``is``, respectively. #. After executing these assignment statements: .. code:: python a = ['a', 5, [], 3.2, [4, 'bc']] b = a[:] have ``a`` and ``b`` the same value? Are they the same object ? You can check it by using the operators ``==`` and ``is``, respectively. #. After executing these assignment statements: .. code:: python a = ['a', 5, [], 3.2, [4, 'bc']] b = a[-1] have ``a[-1]`` and ``b`` the same value? Are they the same object ? You can check it by using the operators ``==`` and ``is``, respectively. #. After executing these assignment statements: .. code:: python a = ['a', 5, [], 3.2, [4, 'bc']] b = [4, 'bc'] have ``a[-1]`` and ``b`` the same value? Are they the same object ? You can check it by using the operators ``==`` and ``is``, respectively. #. Given the following list: .. code:: python a = ['a', 5, [], 3.2, [4, 'bc']] which is the result of the following print expressions ?. You can check it by using the operators ``==`` and ``is``, respectively. .. code:: python >>> b = a >>> print(a, b) >>> b[3] = 'x' >>> print(a, b) >>> a[0] = 10 >>> print(a, b) >>> b = a[-1] >>> b[0] = 'y' >>> print(a, b, a[-1]) #. which is the result of the following print expressions ?. You can check it by using the operators ``==`` and ``is``, respectively. .. code:: python >>> b = [0, 1] >>> a = ['a', b, 'c'] >>> print(a) >>> b[0] = 2 >>> print(b) >>> print(a)