• Python question of the day

    Which of the following code snippets, when executed, will NOT give the output
    [[1, 2, 3], [1, 2, 3], [1, 2, 3]]
     x = [[1, 2, "Hi"]] * 3; x[0][2] = 3; print(x)
     x = [[1, 2, "Hi"]] * 3; x[1][2] = 3; print(x)
     x = [[1, 2, "Hi"]] * 3; x[2][2] = 3; print(x)
     x = [[1, 2, "Hi"]] * 3; x[0][3] = 3; print(x)
    Explanation:
    List assignment index out of range when you access x[0][3] here. Note that the members of the array all point to the same object as we did a shallow copy. What is the difference between a shallow copy and deep copy?


    Top 100 python interview questions:






datai analytics