Python object() Function
Returns a featureless object.
Syntax
Python
Copy Code
object()
The object has all the methods that are common to
all instances of Python class, but because object
does not have
a __dict__
so you can't
assign attributes (properties or methods) to an instance of the new object.
One of the purposes for creating a featureless object is to create a unique
object that can be tested as a "sentinel" value, for example when
using the iter()
function.
Example
Python
Copy Code
class Counter(): n = 0 sentinel = object() def count(self): if (self.n == 5): return self.sentinel self.n += 1 return self.n - 1 counter = Counter() for item in iter(counter.count, counter.sentinel): print(item)
Output
0 1 2 3 4