Contents
Should you reuse variables?
As a general principle, do not reuse variables to point to different objects. This is extremely error prone. In your specific example, since you are recreating the connection object in each call to SqlThingyMethod there is likely no benefit to storing it in a field. Use a local variable.
What does it mean to reassign the value of a variable?
To “assign a variable to a value” is something you do. It means to designate a specific variable to hold a certain value. After you have done this, you intend that the variable will hold that value, but it doesn’t actually hold it yet.
How we assign the one variable value to another?
The first time a variable is assigned a value, it is said to be initialised. The = symbol is known as the assignment operator. It is also possible to declare a variable and assign it a value in the same line, so instead of int i and then i = 9 you can write int i = 9 all in one go.
Can we use same variable name in two methods?
Do not use the same variable name in two scopes where one scope is contained in another. For example, No other variable should share the name of a global variable if the other variable is in a subscope of the global variable.
Can variables from different scope have same name?
Yes — the scopes will not overlap so there will be two local variables, one per method, each with the same name.
How do I assign a variable?
You can assign a value to a routine variable in any of the following ways:
- Use a LET statement.
- Use a SELECT INTO statement.
- Use a CALL statement with a procedure that has a RETURNING clause.
- Use an EXECUTE PROCEDURE INTO or EXECUTE FUNCTION INTO statement.
Which symbol is used to initialize a variable?
Which symbol is used to initialise a variable? Explanation: The symbol, ‘=’, is used to initialise a variable with a particular data type.
Can variable belonging to different scope have same name?
You cant because if you have example(), ‘example’ is a pointer to that function. You can declare local variables with the same name as a global variable, but the local variable will shadow the global. As long as your local a is in scope, the symbol a refers to your local variable.
What’s the difference between optimizing and making it best?
“Optimization” comes from the same root as “optimal”, which means best. When you optimize something, you are “making it best”. But “best” can vary. If you’re a football player, you might want to maximize your running yards, and also minimize your fumbles. Both maximizing and minimizing are types of optimization problems.
What happens when you assign a variable to another variable?
By the time you assign a different reference (and thus object) to a variable, the Garbage Collector will immediately reclaim the space allocated to the previous object, assuming that it is not being referenced by any other variable in the source code: When you store spam = 42 , it creates an object in the memory.
Can a variable be treated as a pointer?
With a mutable object we have to be careful about treating it “like a value” because some other code might mutate it. With an immutable object we have no such concerns. It is correct you can more or less thing of variables as pointers. However example code would help greatly with explaining how this actually is working.
What happens when you add a NUM to a variable?
When we have a = num, nothing is being copied, but now both variables refer to the same object and a is added to the same namespace. This is where my book, Automate the boring stuff with Python, confuses me.