In the first example, your objects don’t overlap in time: one is created then destroyed, then another is created with the same id.
When you compare them with is
, you are holding onto both objects, so they get different ids.
More Related Contents:
- Calling a function of a module by using its name (a string)
- How to access object attribute given string corresponding to name of that attribute
- How to print instances of a class using print()?
- Spawning multiple instances of the same object concurrently in python
- Convert nested Python dict to object?
- Is everything an object in Python like Ruby?
- Referring to the null object in Python
- Getting an instance name inside class __init__() [duplicate]
- super() fails with error: TypeError “argument 1 must be type, not classobj” when parent does not inherit from object
- Python dictionary from an object’s fields
- How can I separate the functions of a class into multiple files?
- Using self.xxxx as a default parameter – Python
- How do I save and restore multiple variables in python?
- python assign values to list elements in loop
- Why is `object` an instance of `type` and `type` an instance of `object`?
- Why do I get a TypeError that says “takes no arguments (1 given)”? [duplicate]
- Why is the cmp parameter removed from sort/sorted in Python3.0?
- What does object’s __init__() method do in python? [duplicate]
- Null object in Python
- How to check if an object has an attribute in Python?
- Why is `self` in Python objects immutable?
- How can I create an object and add attributes to it?
- How to check if an object has an attribute?
- How do I check if an object has an attribute?
- How to clone a Python generator object?
- Why do ints require three times as much memory in Python?
- How to make a copy of a 2D array in Python? [duplicate]
- “Enabling” comparison for classes [duplicate]
- Python object attributes – methodology for access
- Openpyxl check for empty cell