• Python question of the day

    What would be the output of executing the following code:
    original_list = [1, 2, 3, 4]
    new_list = original_list
    new_list[1] = 8
    print(original_list)
     [1, 2, 3, 4]
     [8, 2, 3, 4]
     [1, 8, 3, 4]
     [1, 2, 3, 4, 8]
    Explanation:
    This is a shallow copy and hence oroginal is changed. Shallow copy is a bit-wise copy of an object. A new object is created that has an exact copy of the values in the original object. If any of the fields of the object are references to other objects, just the reference addresses are copied i.e., only the memory address is copied.


    Top 100 python interview questions:






datai analytics