H466 - Global and Local Variables

Quiz
•
Computers
•
12th Grade
•
Easy
R Eveleigh
Used 4+ times
FREE Resource
10 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is a global variable in Python?
A variable that is defined inside a function and can only be accessed within that function.
A variable that is defined outside of all functions and can be accessed by any function in the program.
A variable that is defined inside a loop and can only be accessed within that loop.
A variable that is defined inside a class and can only be accessed by methods of that class.
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is a local variable in Python?
A variable that is defined outside of all functions and can be accessed by any function in the program.
A variable that is defined inside a function and can only be accessed within that function.
A variable that is defined inside a loop and can only be accessed within that loop.
A variable that is defined inside a class and can only be accessed by methods of that class.
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the scope of a variable?
The data type of the variable.
The lifetime of the variable.
The part of the program where the variable can be accessed.
The value assigned to the variable.
4.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the lifetime of a variable?
The duration for which the variable retains its value during the execution of the program.
The part of the program where the variable can be accessed.
The data type of the variable.
The value assigned to the variable.
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
How can you access a global variable inside a function in Python?
By using the `global` keyword before the variable name.
By using the `local` keyword before the variable name.
By using the `global` keyword after the variable name.
By using the `local` keyword after the variable name.
6.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What happens if you try to access a local variable outside its function?
The program will run without any errors.
The program will throw a NameError.
The program will automatically convert it to a global variable.
The program will ignore the variable.
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Which of the following statements is true about the scope of a global variable?
It is limited to the function in which it is defined.
It is limited to the module in which it is defined.
It is accessible throughout the entire program.
It is limited to the class in which it is defined.
Create a free account and access millions of resources
Similar Resources on Wayground
10 questions
Chapter 3 - Think Python - Voc

Quiz
•
9th - 12th Grade
11 questions
Understanding Binary Search Algorithm

Quiz
•
12th Grade
13 questions
Python_OOP_Intro_Quiz

Quiz
•
University
7 questions
Quiz 1

Quiz
•
University
14 questions
python functions

Quiz
•
University
12 questions
Java Class vocabulary

Quiz
•
9th Grade - University
13 questions
C programming-1

Quiz
•
University
15 questions
Java Method

Quiz
•
University
Popular Resources on Wayground
10 questions
Lab Safety Procedures and Guidelines

Interactive video
•
6th - 10th Grade
10 questions
Nouns, nouns, nouns

Quiz
•
3rd Grade
10 questions
9/11 Experience and Reflections

Interactive video
•
10th - 12th Grade
25 questions
Multiplication Facts

Quiz
•
5th Grade
11 questions
All about me

Quiz
•
Professional Development
22 questions
Adding Integers

Quiz
•
6th Grade
15 questions
Subtracting Integers

Quiz
•
7th Grade
9 questions
Tips & Tricks

Lesson
•
6th - 8th Grade
Discover more resources for Computers
20 questions
Digital Citizenship

Quiz
•
8th - 12th Grade
35 questions
Computer Baseline Examination 2025-26

Quiz
•
9th - 12th Grade
13 questions
Problem Solving Process

Quiz
•
9th - 12th Grade
10 questions
Understanding Algorithms with Pseudocode and Flowcharts

Interactive video
•
9th - 12th Grade
19 questions
AP CSP Unit 1 Review (code.org)

Quiz
•
10th - 12th Grade