question archive If we declare a variable called ‘name’ inside of a function while there is a global variable with the same name, which variable is referenced from inside of the function in the following command: print(name)? a
Subject:Computer SciencePrice:2.87 Bought7
If we declare a variable called ‘name’ inside of a function while there is a global variable with the same name, which variable is referenced from inside of the function in the following command: print(name)?
a. |
The global variable |
|||||||||||||
b. |
The local variable |
|||||||||||||
c. |
You cannot have multiple variables with the same name, regardless of scope. |
|||||||||||||
. |
d.you have to specify with a leading com When condtructing a function, which is NOT a minimum requirement:
|
Answer:
1. Answer: b.local variable
Explanation:
So when you define variables inside a function definition, they are local to this function by default. This means that anything you will do to such a variable in the body of the function will have no effect on other variables outside of the function, even if they have the same name. This means that the function body is the scope of such a variable, i.e. the enclosing context where this name with its values is associated.
All variables have the scope of the block, where they are declared and defined in. They can only be used after the point of their declaration.
2)Answer: d. return command