Difference between local,global,instance variable?



Author: Vikas
+0 -0

Local Variable
Local Variable are the variable that declare inside a function or block and the access of that variable is within a function or block.
Static Variable
Static Variable are the variable that declare inside a class and outside the method and we can easily access by their class name.
Instance Variable
Instance Variable are the variable which is unique for every objects.Instance variable are mainly declare with self keyword.We can easily access using object.




Author: Ayush
+0 -0

Local variables exist only within a function's scope and get destroyed after execution. Global variables are declared outside functions and remain accessible unless shadowed by local ones. Instance variables, defined in a class, are tied to specific objects and accessed using self, making them instance-specific.




Author: Riya
+0 -0

Local variables are those declared inside a function and exist only within its scope. They are created when the function is called and destroyed once the function completes execution. Global variables, on the other hand, are defined outside any function or class and are accessible throughout the program, including inside functions unless explicitly shadowed. Instance variables are tied to a specific object and defined within a class using self. They store data specific to each instance, hence enabling objects to maintain their individual states.




Submit Your Response