Replace the list value in python list by using range index

Source Code

thislist = [“keyboard”, “mouse”, “light pen”, “joystick”, “scanner”]

print(“Old List”)

print(thislist)

thislist[1:3] = [“monitor”, “mobile”]

print(“Updated List”)

print(thislist)

Output

Old List

[‘keyboard’, ‘mouse’, ‘light pen’, ‘joystick’, ‘scanner’]

Updated List

[‘keyboard’, ‘monitor’, ‘mobile’, ‘joystick’, ‘scanner’]

Leave a Comment

Your email address will not be published. Required fields are marked *