• Python question of the day

    What would be the output of executing the following code:
    s = [1, 2, 3, 4]
    s[-1 : -5] = ['a']
    print(s)
     ['a']
     [1, 2, 3, 'a']
     [1, 2, 3, 'a', 4]
     IndexError
    Explanation:
    s[-1 :] would replace the last element in the list with the new element, but s[-1 : -5] will append before the last element


    Top 100 python interview questions:


  • python bootcamp 2021
datai analytics