global variable

A variable defined at the top level of a program or module, shared by all the code in that process.

In more detail

Every function can read it; Bash variables are global unless declared local, while Python needs the global statement before a function can assign to one. Globals make it easy for one part of a program to change a value another relies on without anyone noticing, so pass values as arguments instead and keep globals for constants. Each process holds its own copy, and a restart resets it.

Example

HITS = 0  # VI: request state lives in the process, and dies with it

Related terms

Taught in

References

Certification courses