Sail E0 Webinar

MCQs

Total Questions : 9
Question 1. On assigning a value to a variable inside a function, it automatically becomes a global variable. State whether true or false.
  1.    True
  2.    False
  3.    Error
  4.    Not mentioned
 Discuss Question
Answer: Option B. -> False


On assigning a value to a variable inside a function, t automatically becomes a local variable. Hence the above statement is false.


Question 2. Which of these is false about recursion?
  1.    Recursive function can be replaced by a non-recursive function
  2.    Recursive functions usually take more memory space than non-recursive function
  3.    Recursive functions run faster than non-recursive function
  4.    Recursion makes programs easier to understand
 Discuss Question
Answer: Option C. -> Recursive functions run faster than non-recursive function


The speed of a program using recursion is slower than the speed of its non-recursive equivalent.


Question 3. What is the output of the code shown below?l1=[1, 2, 3, [4]]l2=list(l1)id(l1)==id(l2)
  1.    True
  2.    False
  3.    Error
  4.    Address of l1
 Discuss Question
Answer: Option B. -> False


The code shown above shows a nested list. A nested list will undergo shallow copy when the list as a whole undergoes deep copy. Hence the output of this code is False.


Question 4. What happens if a local variable exists with the same name as the global variable you want to access?
  1.    Error
  2.    The local variable is shadowed
  3.    Undefined behavior
  4.    The global variable is shadowed
 Discuss Question
Answer: Option D. -> The global variable is shadowed


If a local variable exists with the same name as the local variable that you want to access, then the global variable is shadowed. That is, preference is given to the local variable.


Question 5. How are keyword arguments specified in the function heading?
  1.    one star followed by a valid identifier
  2.    one underscore followed by a valid identifier
  3.    two stars followed by a valid identifier
  4.    two underscores followed by a valid identifier
 Discuss Question
Answer: Option C. -> two stars followed by a valid identifier




Question 6. Which module in the python standard library parses options received from the command line?
  1.    getopt
  2.    os
  3.    getarg
  4.    main
 Discuss Question
Answer: Option A. -> getopt


getopt parses options received from the command line.


Question 7. What is the type of sys.argv?
  1.    set
  2.    list
  3.    tuple
  4.    string
 Discuss Question
Answer: Option B. -> list


It is a list of elements.


Question 8. How many keyword arguments can be passed to a function in a single function call?
  1.    zero
  2.    one
  3.    zero or more
  4.    one or more
 Discuss Question
Answer: Option C. -> zero or more


zero keyword arguments may be passed if all the arguments have default values.


Question 9. What is the output of the code shown below?def f1():    x=100    print(x)x=+1f1()
  1.    Error
  2.    100
  3.    101
  4.    99
 Discuss Question
Answer: Option B. -> 100


The variable x is a local variable. It is first printed and then modified. Hence the output of this code is 100.


Latest Videos

Latest Test Papers