Class 11 Term 2 Important Questions
Class 11 Term 2 Important Questions
split( ) – It returns a list of words delimited by the specified substring. If no delimiter is given
then words are separated by space.
Example:
>>> str1 = ‘India is a Great Country’
>>>str1.split( )
[‘India’, ‘is’, ‘a’, ‘Great country’]
>>> str1.split(‘a’)
[‘Indi’, ‘ is ‘ , ‘ Gre’, ‘t Country’]
insert( ) - The insert( ) function can be used to insert an element at a specific index position.
This function takes two arguments, the index position and the item.
Syntax: list.insert( index_number, item)
Example:
List1 = [10, 20, 30, 40 ]
List1.insert(2 , 55) # inserting 55 ate the index number 2
extend( ) -The extend() method adds one list at the end of another list.
Syntax: list1.extend( list2 )
Example:
List1 = [10, 20, 30, 40 ]
List2 = [ 50 , 60 ]
List1.extend(List2) # items of List2 will be added in List1
Q3. Difference between pop( ) and popitem( )
pop( ) - pop( ) method deletes and returns the deleted item from the dictionary.
Syntax: dicname.pop(‘key’)
Example:
D1 = {“mon” : “Monday” , “Tue” : “Tuesday”}
D1.pop(‘Tue’)
# it will remove and return element with ‘Tue’ as key from dictionary
popitem( ) - This method removes and returns last item from the dictionary.
Example:
D1 = {“mon” : “Monday” , “Tue” : “Tuesday”}
D1.popitem( ) # it will return and remove last item