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)

6 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. b is wrong

    there is no error in it

    ReplyDelete
  2. 26sandeepkumar12e1619321 July 2021 at 16:52

    for d you have writen wrong statement the error will be
    "TypeError: 'str' object does not support item assignment"

    ReplyDelete
  3. D is wrong
    String is immutable

    ReplyDelete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post