getting_started_with_lists/questions.rst
changeset 522 d33698326409
equal deleted inserted replaced
521:88a01948450d 522:d33698326409
       
     1 Objective Questions
       
     2 -------------------
       
     3 
       
     4 .. A mininum of 8 questions here (along with answers)
       
     5 
       
     6 1. How do you create an empty list? ::
       
     7 
       
     8    empty=[]
       
     9    
       
    10 2. What is the most important property of sequence data types like lists?
       
    11 
       
    12    The elements are in order and can be accessed by index numbers.
       
    13 
       
    14 3. Can you have a list inside a list ? 
       
    15 
       
    16    Yes,List can contain all the other data types, including list. 
       
    17    
       
    18    Example:
       
    19    list_in_list=[2.3,[2,4,6],'string,'all datatypes can be there']
       
    20    
       
    21 4. What is the index number of the first element in a list?
       
    22 
       
    23    0
       
    24    nonempty = ['spam', 'eggs', 100, 1.234]
       
    25    nonempty[0]
       
    26 
       
    27 5. How would you access the end of a list without finding its length?
       
    28 
       
    29    Using negative indices. We can the list from the end using negative indices.
       
    30 
       
    31    ::
       
    32    nonempty = ['spam', 'eggs', 100, 1.234]
       
    33    nonempty[-1]
       
    34 
       
    35 6. What is the function to find the length of a list?
       
    36 
       
    37    len
       
    38 
       
    39 7. Delete the last element from list sq=[5,4,3,2,1,0]
       
    40 
       
    41    del(sq[-1])
       
    42    
       
    43 8. How many will you have to use remove function to remove all 6's from the given list sq=[2,5,6,7,6,4,6]?
       
    44 
       
    45    3
       
    46 
       
    47 Larger Questions
       
    48 ----------------
       
    49 
       
    50 .. A minimum of 2 questions here (along with answers)
       
    51 
       
    52 1. Add all elemets of seq1=['e','f','g','h']
       
    53 to the sequence seq=['a','b','c','d']
       
    54    
       
    55 2. Delete all elements of seq1=[3,5,6] from sequence
       
    56    seq=[1,2,3,4,5,6,7,8,9]