Menu

1 / 2

Quark's Outlines: Python Name Spaces

DEV Community·Mike Vincent·7 months ago
#Tpur1OHo
#problem#how#people#python#name
Reading 0:00
15s threshold

Quark’s Outlines: Python Name Spaces

Overview, Historical Timeline, Problems & Solutions

An Overview of Python Name Spaces

What is a Python name space?

When you write code in Python, you give names to values. A Python name space is the place where those names are stored. It is like a labeled shelf that holds objects. When you ask for a name, Python looks in the shelf to find it.

A name space is a mapping between names and objects. In Python, that mapping is usually a dictionary. Each name space stores the current known names and their values.

Python lets you manage names by storing them in name spaces.

x = 5 print ( globals ()[ " x " ]) # prints: # 5

Enter fullscreen mode

Exit fullscreen mode

The globals() function returns the current global name space. You can look up a name and find its value.

How many name spaces does Python use?

Python uses three main name spaces when running code: local, global, and built-in. Each one is searched in order when Python tries to find a name.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.