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
1
2
3
4
score = 0def add_point():global scorescore += 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.