• Python question of the day

    What would be the output of executing the following code:
    b = [['1'] * 2] * 3
    b[1][1] = 'O'
    print(b)
     [['1', '1'], ['1', 'O'], ['1', '1']]
     [['1', '1', '1'], ['1', '1', 'O']]
     [['1', '1', '0'], ['1', '1', 'O']]
     [['1', 'O'], ['1', 'O'], ['1', 'O']]
    Explanation:
    The outer list is made of three references to the same inner list. Since all rows are aliases referring to the same object, it will be updated at all the three places


    Top 100 python interview questions:


datai analytics