In python you should avoid using global variables because
python computes local variables quicker
global variables increase scope and memory footprint
global variables override local variables
why do we want to write efficient code
we want to reduce the runtime
we want to reduce the memory footprint of the code
we want to reduce the statements in the code
we want to reduce the compile time of the code
why do we refactor code
to rename code to following an intention revealing name
we want to encapsulate fields
we want to extract classes
we want to pushdown methods to protect them in a class
note: there may be more than one answer in each questions!!
Transcribed text From Image:
Expert Chegg Question Answer:
** In python you should avoid using global variables because global variables have no access control i.e increases scope and memory footprint by causing namespace pollution.
–> Therefore the answer is option(2).
** We want to write efficient code because it decreases the time and space complexity by increasing the functionality of the code with minimum number of statements.
–> Therefore the answer is options (1), (2), (3) and (4).
As we strictly instructed to solve only the first question. So I have solved two questions for your convenience. Hope you understand