AI engineering glossary · Python core

What is global keyword?

global keyword: A statement that declares a name inside a function to refer to the module-level variable, so that assignments change the global instead of creating a local. Overuse makes code hard to follow.

Level: intermediateTopic: Python core

global keyword: an example

count = 0; def inc(): global count; count += 1 raises the module's count; without global it raises UnboundLocalError.

Related terms

More Python core terms

Where you learn it

global keyword is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.

Before you go

Take the cheat sheet with you

One free PDF: the key AI-engineering terms, formulas and Python idioms. No spam; unsubscribe any time.