Q. What does each of the following expressions evaluate to? Suppose that T is the tuple

 

("These", ("are", "a", "few", "words"), "that", "we", "will", "use")

 

(a)

T[1][0: : 2]

 

(b)

"a" in T [1] [ 0 ]

 

(c)

T [ : 1 ] + T[ 1 ]

 

(d)

T[ 2 : : 2 ]

 

(e)

T[2][2] in T[1]

 

Answer =

Output are follow:-

 

(a)

>>> T[1][0: : 2]

('are', 'few')

 

(b)

>>> "a" in T [1] [ 0 ]

True

 

(c)

>>> T [ : 1 ] + T[ 1 ]

('These', 'are', 'a', 'few', 'words')

 


(d)

>>> T[ 2 : : 2 ]

('that', 'will')

 

(e)

>>> T[2][2] in T[1]

True

>>> 

16 Comments

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

  1. In c, it should produce an error due to addends of different types, please correct

    ReplyDelete
    Replies
    1. No, it is correct please try it your idle python.

      Delete
  2. your answer of a and c is wrong because in a I was run so output is [''are'',''few''] it is in list and in c it gives error because we never concatenate (+) list and tuple

    ReplyDelete
    Replies
    1. You are wrong question is for tuple.

      Delete
    2. path wala you guys are wrong

      Delete
  3. c is wrong i tried in idle ok

    ReplyDelete

Post a Comment

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

Previous Post Next Post