
Python Global Variables
Presentation
•
Computers
•
8th Grade
•
Practice Problem
•
Medium
Mark Christensen
Used 5+ times
FREE Resource
8 Slides • 13 Questions
1
2
Global Variables
Variables that are created outside of a function are known as global variables.
Global variables can be used by everyone, both inside of functions and outside.
Subject | Subject
3
Create a variable outside of a function, and use it inside the function.
Notice how the variable is created outside of the function, but it is being used inside of the function.
4
Fill in the Blanks
What is the global variable?
Type answer...
5
Fill in the Blanks
What will be displayed when this code is ran?
Type answer...
6
Global vs Local
If you create a variable with the same name inside a function, this variable will be local, and can only be used inside the function. The global variable with the same name will remain as it was, global and with the original value.
Subject | Subject
7
Create a variable inside a function, with the same name as the global variable
Notice how the variable inside of the function has a different value than the Global variable.
8
Multiple Choice
What is the value GLOBAL variable?
awesome
fantastic
Python is
myfunc( )
9
Multiple Choice
What is the value LOCAL variable?
awesome
fantastic
Python is
myfunc( )
10
The global Keyword
Normally, when you create a variable inside a function, that variable is local, and can only be used inside that function.
To create a global variable inside a function, you can use the global keyword.
Subject | Subject
11
If you use the global keyword, the variable belongs to the global scope.
If the variable is inside of the function and if the variable isn't declared as being global, it is considered local.
12
Fill in the Blanks
When the function is ran, what will be displayed?
Type answer...
13
Fill in the Blanks
Before the function is ran, what is the GLOBAL value of points?
Type answer...
14
Fill in the Blanks
Before the function is ran, what is the LOCAL value of points?
Type answer...
15
When you try to modify the global variable value inside a function, it will throw UnboundLocalError, because while modifying Python treats points as a local variable, but points is also not defined inside the function myfunc( ). It will need to be declared as a global variable to work properly.
16
Fill in the Blanks
Write the code that needs to be added to line 4 in order for the function to add 1 point to the global variable.
Type answer...
17
Multiple Choice
Which of the following is...
#defining a local variable
def superfunc( )
x = fantastic
print("Python is" + x)
superfunc()
18
Multiple Choice
Which of the following is...
#defining a function
def superfunc( )
x = fantastic
print("Python is" + x)
superfunc()
19
Multiple Choice
Which of the following is...
#accessing a local variable
def superfunc( )
x = fantastic
print("Python is" + x)
superfunc()
20
Multiple Choice
Which of the following is...
#calling the function
def superfunc( )
x = fantastic
print("Python is" + x)
superfunc()
21
Fill in the Blanks
Write the code that needs to be added to line 3 in order for the global variable to work properly.
Type answer...
Show answer
Auto Play
Slide 1 / 21
SLIDE
Similar Resources on Wayground
16 questions
Newton's First Law of Motion...
Presentation
•
8th Grade
16 questions
Slope Review
Presentation
•
8th Grade
18 questions
Code.orge Unit 2 Lessons 1-3
Presentation
•
7th - 8th Grade
14 questions
Artificial Intelligence Revision
Presentation
•
8th Grade
16 questions
8.7 c tides
Presentation
•
8th Grade
16 questions
SS8H4b
Presentation
•
8th Grade
16 questions
Subject-Object Pronouns (Compound)
Presentation
•
8th Grade
16 questions
Comparatives & Superlatives
Presentation
•
8th Grade
Popular Resources on Wayground
10 questions
Safety Day 2026 – Student Review
Quiz
•
9th Grade
21 questions
Continents and Oceans
Quiz
•
6th Grade
20 questions
Parts of Speech
Quiz
•
5th Grade
16 questions
Subject & Predicate
Quiz
•
5th Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
12 questions
Map Skills
Quiz
•
3rd Grade
22 questions
Continents and Oceans
Quiz
•
5th Grade
15 questions
Rounding Decimals
Quiz
•
5th Grade