CHAPTER 5

SCOPE

CHAPTER OUTLINE

5.1 Objects and Object IDs

5.2 Scope of Objects and Names

In this chapter, we will review the objects and their mapping to names, the scope of names and parameter passing mechanisms in Python. Recall that in Python, the terms name and variable are used as synonyms.

5.1 OBJECTS AND OBJECT ids

Each object in Python is assigned a unique identifier that can be accessed using the function id.

 

each Python object has a unique identifier

 

image

Fig. 5.1 Program to illustrate objects and their ids (objectId.py)

On an execution of the above script (Fig. 5.1), it produced the following output:

variables a and b refer to ...

Get Python Programming: A modular approach now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.