Correct option is A
The statement
"global immutable variables require global keyword inside function" is
false. In Python,
global immutable variables (like integers, strings, or tuples) do
not require the global keyword when accessed inside a function. You only need the global keyword if you intend to modify the global variable inside the function.
Important Key Points:
1.
Global Variables: Global variables are those defined outside of any function and can be accessed anywhere in the program.
2.
Accessing Global Variables: Global variables can be accessed directly inside functions, but if you intend to modify them, you must use the global keyword.
3.
Immutable Global Variables: For
immutable types (like integers, strings, tuples), you do not need the global keyword to access them. However, if you want to reassign them inside a function, you must use global.
4.
Mutable Global Variables: For
mutable types (like lists or dictionaries), you can modify them without using the global keyword, but reassigning them would require the global keyword.
Knowledge Booster:
·
Option (b): This is
true.
Global mutable variables (such as lists or dictionaries) can be modified inside a function without needing the global keyword. However, reassigning them entirely requires the global keyword.
·
Option (c): This is
true. The
global keyword is necessary for the first assignment of a global variable inside a function. If you do not use global, Python will create a local variable instead of modifying the global one.
·
Option (d): This is
true.
Global variables can be accessed from anywhere in the program, inside or outside of functions, as long as they are not shadowed by local variables with the same name.