Q. Find the errors. State reasons.
(a)
t = (1, "a", 9.2)
t[0] = 6
(b)
t = [1, "a", 9.2]
t[0] = 6
(c)
t = [1, "a", 9.2]
t[4] = 6
(d)
t = 'hello'
t[0] = "H"
(e)
for Name in [Amar, Shveta, Parag]
IF Name[0] = 'S' :
print(Name)
Answer =
(a)
Tuple is immutable data type , so we cannot change its element
(b)
No error .
(c)
It give error (“out of index”) , because index 4 not exist.
(d)
String is immutable data type, so we cannot change its element
(e)
Correct program -
for Name in ["Amar", "Shveta", "Parag"]:
if Name[0] == 'S' :
print(Name)
b is wrong
ReplyDeletethere is no error in it
Right : )
Deletefor d you have writen wrong statement the error will be
ReplyDelete"TypeError: 'str' object does not support item assignment"
Yes, Sorry for wrong answer.
DeleteD is wrong
ReplyDeleteString is immutable
Yes, Sorry for wrong answer.
DeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )