advanced-features-functions/questions.rst
changeset 522 d33698326409
parent 521 88a01948450d
child 523 54bdda4aefa5
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. All arguments of a function cannot have default values. True or
       
     7    False? 
       
     8 
       
     9    Answer: False
       
    10    
       
    11 #. When calling a function, the arguments 
       
    12 
       
    13    1. should always be in the order in which they are defined.
       
    14    #. can be in any order
       
    15    #. only keyword arguments can be in any order, but should be called
       
    16       at the beginning.
       
    17    #. only keyword arguments can be in any order, but should be called
       
    18       at the end.
       
    19 
       
    20    Answer: only keyword arguments can be in any order, but should be called
       
    21            at the end.
       
    22 
       
    23 #. Given the following function, identify the keywords with default
       
    24    values. 
       
    25    ::
       
    26    
       
    27      def seperator(char, count=40, show=False):
       
    28 
       
    29          if show:
       
    30              print char * count
       
    31 
       
    32          return char * count
       
    33 
       
    34    Answer: ``count``, ``show``
       
    35 
       
    36 #. Given the following function, 
       
    37    ::
       
    38    
       
    39      def seperator(char, count=40, show=False):
       
    40 
       
    41          if show:
       
    42              print char * count
       
    43 
       
    44          return char * count
       
    45 
       
    46    What is the output of ``separator("+", 1, True)``.
       
    47 
       
    48    Answer: ``+`` is printed and returned. 
       
    49 
       
    50 
       
    51 #. Given the following function, 
       
    52    ::
       
    53    
       
    54      def seperator(char, count=40, show=False):
       
    55 
       
    56          if show:
       
    57              print char * count
       
    58 
       
    59          return char * count
       
    60 
       
    61    What is the output of ``separator("+", True, 1)``.
       
    62 
       
    63    Answer: ``+`` is printed and returned. 
       
    64 
       
    65 #. Given the following function, 
       
    66    ::
       
    67    
       
    68      def seperator(char, count=40, show=False):
       
    69 
       
    70          if show:
       
    71              print char * count
       
    72 
       
    73          return char * count
       
    74 
       
    75    What is the output of ``separator("+", show=True, 1)``.
       
    76 
       
    77    Answer: SyntaxError
       
    78 
       
    79 #. The following is a valid function definition. True or False? Why?
       
    80    ::
       
    81    
       
    82      def seperator(count=40, char, show=False):
       
    83 
       
    84          if show:
       
    85              print char * count
       
    86 
       
    87          return char * count
       
    88 
       
    89    Answer: False. All parameters with default arguments should be
       
    90    defined at the end. 
       
    91 
       
    92 #. Which of the following cannot be used as default values for
       
    93    arguments? 
       
    94      
       
    95    a. floats
       
    96    #. lists
       
    97    #. functions
       
    98    #. booleans
       
    99    #. None of the Above
       
   100 
       
   101    Answer: None of the above. 
       
   102 
       
   103 
       
   104 Larger Questions
       
   105 ----------------
       
   106 
       
   107 1. 
       
   108 
       
   109 2.