Page 187 - Information_Practice_Fliipbook_Class11
P. 187
C T 01 1. lst = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
For each of the following lists, give a slice that would extract it from the list lst.
a. ['c', 'd', 'e', 'f']
b. ['a', 'b', 'c']
c. ['e', 'f', 'g']
d. ['a', 'd']
e. ['b', 'd']
f. Second to the last element of the list
2. Suppose we have the following assignment statements:
s1 = 'I wish to score highest marks.'
s2 = ['I', 'wish', 'to', 'score', 'highest', 'marks', '.']
Which of the following statements will execute without any errors?
a. s2[0]= 'You'
b. s1[29]='!'
c. s2[6]='!'
7.1.4 Membership operator in
The membership operator in is used to check the membership of an element in a list. It returns True if the specific
element being looked for is present in the list, otherwise, False.
Example:
>>> colors = ['red', 'green', 'blue', 'yellow', 'orange', 'white', 'black']
>>> 'yellow' in colors
True
>>> 'pink' in colors
False
7.1.5 Membership operator not in
The membership operator not in is used to check the membership of an element in a list. It returns True if the
specific element being looked for is not present in the list, otherwise, False.
Example:
>>> 'pink' not in colors
True
7.2 List Assignment
A list assignment does not create a new copy of the list. Instead, on the execution of the assignment statement, the
variable on the left-hand side of the assignment statement refers to the list on the right-hand side of the assignment
statement; for example,
>>> colors ['red', 'green', 'blue']
>>> colorsRef = colors
>>> id(colors)
Python Lists 173

