Q. What does each of the following expressions evaluate to?


Suppose that L is the list


["These", ["are", "a"], ["few", "words"], "that", "we", "will", "use"]


(a) L[3:4] + L[1:2]

(b) "few" in L[2:3]

(c) "few" in L[2]

(d) 4[2][1:]

(e) L[1]+[2]


Answer :-

(a)
L[3:4] = ['that']
L[1:2] = [['are', 'a']]
L[3:4] +L[1:2] = ['that', ['are', 'a']]

(b) False. The string "few" is not an element of this range. L[2:3] returns a list of elements from L-> [['few', 'words']], this is a list with one element, a list.

(c) True. L[2] returns the list ['few', 'words'], "few" is an element of this list.

(d)
L[2] = ['few, 'words']
L[2][1:] = ['words']

(e)
L[1] = ['are', 'a']
L[2] = ['few', words']
L[1] + L[2] = ['are', 'a', 'few, 'words']

Post a Comment

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

Previous Post Next Post