SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Tony Gaddis
Chapter:
Lists And Tuples
Exercise:
Checkpoint
Question:1 | ISBN:9780132576376 | Edition: 2

Question

What will the following code display?
numbers = [1, 2, 3, 4, 5]
numbers[2] = 99
print(numbers)

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

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

 

0 0

Discussions

Post the discussion to improve the above solution.