What will the following code display?
numbers = [1, 2, 3, 4, 5]
numbers[2] = 99
print(numbers)
The ouput of the given is:
[1, 2, 99, 4, 5]
Explanation:we get the above output,Since The list is a data type that is mutable. Once a list has been created: Elements can be modified. Individual values can be replaced.
Here from list numbers, number[2] is 3 . As we want to replace 3 with 99 i.e,number[2]=99. Hence the final result obtained is [1,2,99,4,5].
The complete executable code with comments:
numbers = [1, 2, 3, 4, 5] #assigning values to list numbers
numbers[2] = 99 #replacing the value in index 2 with 99
print(numbers) #print the final list