Python Programming - Variables - Discussion
Discussion Forum : Variables - General Questions (Q.No. 13)
13.
What is the difference between a global variable and a local variable?
Answer: Option
Explanation:
In Python, a global variable is a variable that is defined outside of any function and can be accessed from anywhere in the code. A local variable, on the other hand, is a variable that is defined within a function and can only be accessed within that function.
Global variables exist throughout the entire program's execution, while local variables are created when a function is called and are destroyed when the function completes. Therefore, global variables have a longer lifespan than local variables.
Discussion:
Be the first person to comment on this question !
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers