Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Language feature: global keyword #12

Open
tusharsadhwani opened this issue Aug 16, 2023 · 0 comments
Open

Language feature: global keyword #12

tusharsadhwani opened this issue Aug 16, 2023 · 0 comments

Comments

@tusharsadhwani
Copy link
Owner

Using the global keyword helps define the scope of a specific variable inside a function.

For example:

x = 0

def foo():
    x = 1

foo()
print(x)  # still 0

But, using global:

x = 0

def foo():
    global x  # now, we know to always get/set x from global scope.
    x = 1

foo()
print(x)  # 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant