Music, asked by mayank4171, 1 year ago

7. 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[1][0::2]
(b) "a" in L[1][0]
(c) L[:1] + [1]
(d) L[2::2]
(e) L[2][2] in L[1]​

Answers

Answered by Equestriadash
33

Given list:

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

Output for each statement:

(a) L[1][0::2]

  • ['are', 'few']

L[1] = ["are", "a", "few", "words"]

L[1][0::2] = ["are", "few"], taking the start value as position 0, and step value as 2.

(b) "a" in L[1][0]

  • True

L[1][0] = 'are'

"a" in L[1][0] checks for the character 'a' in that element.

(c) L[:1] + L[1]

  • ['These', 'are', 'a', 'few', 'words']

L[:1] = ['These']

L[1] = ['are', 'a', 'few', 'words']

Concatenating both, ['These', 'are', 'a', 'few', 'words'].

(d)  L[2::2]

  • ['that', 'will']

Taking the start value as position 2, and step value as 2.

(e) L[2][2] in L[1]​

  • True

L[2][2] = 'a'

L[1] = ['are', 'a', 'few', 'words']

Checks if the element in L[2][2] is in L[1].

Answered by Anonymous
7

Answer:

Given list:

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

Output for each statement:

(a) L[1][0::2]

['are', 'few']

L[1] = ["are", "a", "few", "words"]

L[1][0::2] = ["are", "few"], taking the start value as position 0, and step value as 2.

(b) "a" in L[1][0]

True

L[1][0] = 'are'

"a" in L[1][0] checks for the character 'a' in that element.

(c) L[:1] + L[1]

['These', 'are', 'a', 'few', 'words']

L[:1] = ['These']

L[1] = ['are', 'a', 'few', 'words']

Concatenating both, ['These', 'are', 'a', 'few', 'words'].

(d)  L[2::2]

['that', 'will']

Taking the start value as position 2, and step value as 2.

(e) L[2][2] in L[1]

True

L[2][2] = 'a'

L[1] = ['are', 'a', 'few', 'words']

Checks if the element in L[2][2] is in L[1].

Similar questions