What will be the output of the following Python code?
a) [[1, 2], [3, 1.5], [0.5, 0.5]]
b) [[3, 1.5], [1, 2], [0.5, 0.5]]
c) [[0.5, 0.5], [1, 2], [3, 1.5]]
d) [[0.5, 0.5], [3, 1.5], [1, 2]]
Explanation: Execute in the shell to verify.
What will be the output of the following Python code?
a) [10,34,56,[95]]
b) [10,23,56,[78]]
c) [10,23,56,[95]]
d) [10,34,56,[78]]
Explanation: The above copy is a type of shallow copy and only changes made in sublist is reflected in the copied list.
What will be the output of the following Python code?
a) [10,34,56,[95]]
b) [10,23,56,[78]]
c) [10,23,56,[95]]
d) [10,34,56,[78]]
Explanation: The above copy is deepcopy. Any change made in the original list isn’t reflected.
What will be the output of the following Python code?
a) 10
b) [1,3,5,7]
c) 4
d) [1,3,6,10]
Explanation: The above code returns the cumulative sum of elements in a list.
What will be the output of the following Python code?
a) Syntax error
b) [[7], [7], [7]]
c) [[7], [], []]
d) [[],7, [], []]
Explanation: The first line of the code creates multiple reference copies of sublist. Hence when 7 is appended, it gets appended to all the sublists.
What will be the output of the following Python code?
a) [3, 7, 8, 6, 1, 2]
b) Syntax error
c) [3,[7,8],6,1,2]
d) [3,4,6,7,8]
Explanation: In the piece of code, slice assignment has been implemented. The sliced list is replaced by the assigned elements in the list. Type in python shell to verify.