capypad
0 day streak
python / beginner
Snippet

The Global Keyword

The 'global' keyword allows you to modify a variable that is defined outside the current function's scope.

snippet.py
python
1
2
3
4
score = 0
def add_point():
global score
score += 1
Breakdown
1
global score
Tells Python to use the 'score' variable from the main script level.
2
score += 1
Increments the global variable by one.