Answer to Question #93043 in Python for Lokeshwaran

Question #93043
One of the following 10 statements generates an error. Which one? (Your answer should be a number between 1 and 10.)

x = [1,"abcd",2,"efgh",[3,4]] # Statement 1
y = x[0:50] # Statement 2
z = y # Statement 3
w = x # Statement 4
x[1] = x[1] + 'd' # Statement 5
y[2] = 4 # Statement 6
x[1][1] = 'y' # Statement 7
z[0] = 0 # Statement 8
w[4][0] = 1000 # Statement 9
a = (x[4][1] == 4)
1
Expert's answer
2019-08-22T03:34:33-0400

There is mistake in the statement 7:

x[1][1] = 'y'


Before this statement, the value in x equals 'abcdd'. It has the type string.

String in Python is the immutable type (documentation: https://docs.python.org/3/library/stdtypes.html). That why we can’t change the string by index.


If you run this code, you will get the following message:


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS