---
title: "What are Python’s namespaces?"  
description: "What are Python’s namespaces?"  
author: "ICSM Computer"  
published: 2025-09-14  
updated: 2025-09-14  
canonical: https://www.mindstick.com/interview/34371/what-are-python-s-namespaces  
category: "python"  
tags: ["python-3.4", "Python 3"]  
reading_time: 2 minutes  

---

# What are Python’s namespaces?

There are four types of namespaces used in Python programing.

1. **Built-in namespace** → functions like `len()`, `print()`.
2. **Global namespace** → variables in the main program.
3. **Local namespace** → variables inside a function.
4. **Enclosing namespace** → outer function variables in nested functions.

Remembering **LEGB Rule**: **Local** → **Enclosing** → **Global** → **Built-in.**

## Read More -

- [**Find duplicate elements in a list**](https://www.mindstick.com/interview/34370/find-duplicate-elements-in-a-list)
- [**Find the largest number in a list**](https://www.mindstick.com/interview/34367/find-the-largest-number-in-a-list)
- [**Count Word Frequency in a String with explanation**](https://www.mindstick.com/interview/34366/count-word-frequency-in-a-string-with-explanation)
- [**Write a Python program to reverse a given string. with explanation**](https://www.mindstick.com/interview/34365/write-a-python-program-to-reverse-a-given-string-with-explanation)

## Answers

### Answer by ICSM Computer

There are four types of namespaces used in Python programing.

1. **Built-in namespace** → functions like `len()`, `print()`.
2. **Global namespace** → variables in the main program.
3. **Local namespace** → variables inside a function.
4. **Enclosing namespace** → outer function variables in nested functions.

Remembering **LEGB Rule**: **Local** → **Enclosing** → **Global** → **Built-in.**

## Read More -

- [**Find duplicate elements in a list**](https://www.mindstick.com/interview/34370/find-duplicate-elements-in-a-list)
- [**Find the largest number in a list**](https://www.mindstick.com/interview/34367/find-the-largest-number-in-a-list)
- [**Count Word Frequency in a String with explanation**](https://www.mindstick.com/interview/34366/count-word-frequency-in-a-string-with-explanation)
- [**Write a Python program to reverse a given string. with explanation**](https://www.mindstick.com/interview/34365/write-a-python-program-to-reverse-a-given-string-with-explanation)


---

Original Source: https://www.mindstick.com/interview/34371/what-are-python-s-namespaces

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
