Variable Scope in Python

The extraordinary short guide to Pythons crazy scoping rules

Martin Thoma
Towards Data Science
4 min readNov 22, 2020

--

Image by author (source)

It’s obvious that you cannot access a variable before it was declared. But if it was declared inside a loop, can you access it outside a loop? If it was declared in a function, can you access the variable outside of the function?

--

--