diff -r 88a01948450d -r d33698326409 advanced_features_of_functions/questions.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/advanced_features_of_functions/questions.rst Wed Dec 01 16:51:35 2010 +0530 @@ -0,0 +1,109 @@ +Objective Questions +------------------- + +.. A mininum of 8 questions here (along with answers) + +1. All arguments of a function cannot have default values. True or + False? + + Answer: False + +#. When calling a function, the arguments + + 1. should always be in the order in which they are defined. + #. can be in any order + #. only keyword arguments can be in any order, but should be called + at the beginning. + #. only keyword arguments can be in any order, but should be called + at the end. + + Answer: only keyword arguments can be in any order, but should be called + at the end. + +#. Given the following function, identify the keywords with default + values. + :: + + def seperator(char, count=40, show=False): + + if show: + print char * count + + return char * count + + Answer: ``count``, ``show`` + +#. Given the following function, + :: + + def seperator(char, count=40, show=False): + + if show: + print char * count + + return char * count + + What is the output of ``separator("+", 1, True)``. + + Answer: ``+`` is printed and returned. + + +#. Given the following function, + :: + + def seperator(char, count=40, show=False): + + if show: + print char * count + + return char * count + + What is the output of ``separator("+", True, 1)``. + + Answer: ``+`` is printed and returned. + +#. Given the following function, + :: + + def seperator(char, count=40, show=False): + + if show: + print char * count + + return char * count + + What is the output of ``separator("+", show=True, 1)``. + + Answer: SyntaxError + +#. The following is a valid function definition. True or False? Why? + :: + + def seperator(count=40, char, show=False): + + if show: + print char * count + + return char * count + + Answer: False. All parameters with default arguments should be + defined at the end. + +#. Which of the following cannot be used as default values for + arguments? + + a. floats + #. lists + #. functions + #. booleans + #. None of the Above + + Answer: None of the above. + + +Larger Questions +---------------- + +1. + +2.