Class 9 List Notes
Class 9 List Notes
Lists
Rationalised 2023-24
Rationalised 2023-24
9.2.2 Repetition
Python allows us to replicate a list using repetition
operator depicted by symbol *.
>>> list1 = ['Hello']
#elements of list1 repeated 4 times
>>> list1 * 4
['Hello', 'Hello', 'Hello', 'Hello']
9.2.3 Membership
Like strings, the membership operators in checks if
the element is present in the list and returns True, else
returns False.
>>> list1 = ['Red','Green','Blue']
>>> 'Green' in list1
True
>>> 'Cyan' in list1
False
The not in operator returns True if the element is not
present in the list, else it returns False.
>>> list1 = ['Red','Green','Blue']
>>> 'Cyan' not in list1
True
>>> 'Green' not in list1
False
Rationalised 2023-24
#negative indexes
#elements at index -6,-5,-4,-3 are sliced
>>> list1[-6:-2]
['Green','Blue','Cyan','Magenta']
Rationalised 2023-24
len() Returns the length of the list passed as >>> list1 = [10,20,30,40,50]
the argument >>> len(list1)
5
Rationalised 2023-24
[ ]
Creates a list if a sequence is passed as >>> str1 = 'aeiou'
an argument >>> list1 = list(str1)
>>> list1
['a', 'e', 'i', 'o', 'u']
Rationalised 2023-24
>>> list1
[10, 20, 30, 40, 50]
reverse() Reverses the order of elements in the >>> list1 = [34,66,12,89,28,99]
given list >>> list1.reverse()
>>> list1
[ 99, 28, 89, 12, 66, 34]
Rationalised 2023-24