Python Global vs. Local Variables Quiz

Master Quiz: Global vs. Local Variables

🎩 Master Quiz: Global vs. Local

20 Questions to test your Scope management skills.
Green = Correct, Red = Incorrect.

BeginnerAnalogy

In the Office Analogy, what represents a Local Variable?

BeginnerScope

Where are Global Variables created?

IntermediateAccess Rule

Can a function read (print) a Global variable without special keywords?

IntermediateBehavior

What happens if you type x = 10 inside a function, but x already exists globally?

ArchitectCode Smell

Why are excessive Global Variables considered a “Code Smell”?

AdvancedKeywords

Which keyword allows you to modify a global variable inside a function?

IntermediateLifetime

When does a Local Variable “die” (get removed from memory)?

ArchitectLEGB Rule

What is the order in which Python looks for variables?

AdvancedMutable Globals

If logs = [] is global, can a function do logs.append("Error") without the global keyword?

AdvancedError Handling

What causes UnboundLocalError: local variable referenced before assignment?

ArchitectNaming Convention

What is the best practice naming convention for Global Constants?

BeginnerIsolation

If Function A has x=10 and Function B has x=20, do they interfere?

IntermediateUse Cases

Which of these is a good candidate for a Local Variable?

ArchitectSecurity

Where should sensitive data like a user’s password be stored?

IntermediateCode Analysis
x = 5
def test():
    print(x)
test()

What is the output?

IntermediateCode Analysis
x = 5
def test():
    x = 10
    print(x)
test()
print(x)

What is the output?

AdvancedZombie Variables

What is a “Zombie Variable”?

ArchitectMemory

Which type of variable relies on Garbage Collection happening “sooner”?

BeginnerAccess

Can the main script access a variable created inside a function?

IntermediateExplicit Declaration

If you want to read a global variable, do you NEED to write global x?

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top