Question 14

Which of the following is false about global variables in Python?

  1. AGlobal immutable variables require global keyword inside function.
  2. BGlobal mutable variables do not require global keyword inside function.
  3. CGlobal keyword is a must for the first time of assignment of a global variable.
  4. DGlobal variables can be accessed any where in the program.
Show answerHide answer

Correct answer: (C) Global keyword is a must for the first time of assignment of a global variable.

Explanation

A variable assigned at the top level of a module is already global, so no global keyword is needed for that first assignment. The keyword is needed only when a function wants to rebind a global name.

From DSSSB TGT Computer Science Practice Set 1

This is question 14 of DSSSB TGT Computer Science Practice Set 1. See all questions of this paper with answers, or attempt the paper as a timed online test to get your score and all-India rank.