0% found this document useful (0 votes)
23 views3 pages

Class 11 Term 2 Important Questions

Important Questions class 11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views3 pages

Class 11 Term 2 Important Questions

Important Questions class 11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Rising Academy

Computer Science – Class 11


Term 2 Important Questions and Answers
Q1. Difference between split() and partition()
partition( ) – It divides the given string at the first occurrence of the substring and returns the
string into three parts.
1. Substring before the separator
2. Separator
3. Substring after the separator
If the separator is not found in the string, it returns the whole string itself and two empty
strings.
Example:
>>> str1 = ‘India is a Great Country’
>>> str1.partition(‘is’)
(‘India’, ‘is’, ‘a Great Country’)
>>> str1.partition(‘are’)
(‘India is a Great Country’, ‘ ’ , ‘ ’ )

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’]

Q2. Difference between append( ), insert( ) and extend( )


append( ) - The append( ) method adds a single item to the end of the list. Single element can
be integer, string or a list.
Syntax: list.append( item )
Example:
List1 = [10, 20, 30, 40 ]
List1.append(55) # adding integer element
List1.append( [50,60] ) # adding a list element

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

Q4. Difference between find( ) and index( )

Q5. Difference between slicing and indexing


Indexing - There is an index value for each item present in the sequence (string/list/tuple).
Index of the first element in the list is 0, second element is 1. The index number -1 identifies
the last element.
Example:
>>> List1 = [10,20,30,40,50]
>>> print(List1[1])
>>> print(List1[-1])
Output:
10
50
Slicing - We can slice (cut) a particular range from a list using slicing. Slicing creates a sub
part of a list.
Syntax for slicing is list[start: stop: step]
Example
>>> X = [‘c’, ‘o’, ‘m’, ‘p’, ‘u’, ‘t’, ‘e’, ‘r’]
>>> x[1: 4]
>>>x[ : -2]
Output:
[‘o’, ‘m’, ‘p’]
[‘c’, ‘o’, ‘m’, ‘p’, ‘u’, ‘t’]

You might also like