Logo

Question preview

globals()

What this preview is

About this preview

globals() is a easy quant interview question on language knowledge in Python.

Unlock full access to getcracked

Join to unlock this question, detailed solutions, and our complete library of quant finance interview prep.

Understanding Python's globals() function and namespace access

This is an easy Python question that tests your grasp of how Python manages the global namespace and what the globals() built-in returns at runtime. It's a useful conceptual check for anyone writing or debugging Python code, especially in environments where dynamic variable lookup matters.

The question asks you to trace through a code snippet and predict what gets printed—or whether an error occurs instead. To answer it correctly, you need to understand what globals() actually is, how it relates to module scope, and when you might encounter a NameError or other runtime exception. This kind of reasoning is particularly relevant when working with introspection, metaprogramming, or dynamic imports.

  • The distinction between the global namespace and the globals() dictionary
  • How variable binding works at module scope
  • When name lookups fail and exceptions are raised