Python Reference Library →

Python object() Function – Base Object Constructor Explained

Let’s look at object() function – base object constructor explained

  1. Notice

    object() constructs a basic object. Distinct live objects have different identities even when they share the same type.

  2. Try

    Follow the example, change its sample, and compare what happens.

  3. Check

    Explain the result and test your understanding.

Watch how it works

Focus on how the names, objects, and calculations change. We’ll inspect the printed output in the next section.

Explore the idea

Follow the code and watch its state change. Guided simulation.

Code
Python
items = [object() for _ in range(3)]
print(len(items))
print(type(object()).__name__)
Live state

Top-level scope

items→Object 4
Object 4 · list[<object object>, <object object>, <object object>]
This step

object() constructs a basic object. Distinct live objects have different identities even when they share the same type.

Picture object() function – base object constructor explained

object() constructs a basic object. Distinct live objects have different identities even when they share the same type.

Image brief

Alt text
A diagram for Python object() Function – Base Object Constructor Explained. Instructions: items = [object() for _ in range(3)] print(len(items)) print(type(object()).__name__). Displayed result: 3 object. The final example bindings are items --> object 4 (list). object 4: [<object object>, <object object>, <object object>]
Image generation prompt
Create a clean educational illustration for a Python programming lesson titled "Python object() Function – Base Object Constructor Explained". Teaching focus: object() constructs a basic object. Distinct live objects have different identities even when they share the same type. Depict exactly the relationships and labels in this reference diagram: EXAMPLE INSTRUCTIONS items = [object() for _ in range(3)] print(len(items)) print(type(object()).__name__) | v DISPLAYED RESULT 3 object FINAL BINDINGS items --> object 4 (list) object 4: [<object object>, <object object>, <object object>] Use a flat vector style, generous spacing, clear arrows and legible labels, with a restrained blue/teal palette on a plain background. The diagram must explain the programming idea accurately. Do not depict variables as boxes containing copied objects when they share a reference. Avoid mascots, decorative screenshots, logos, gradients and extra text. Landscape composition, approximately 3:2, suitable for a course card. Accessible description: A diagram for Python object() Function – Base Object Constructor Explained. Instructions: items = [object() for _ in range(3)] print(len(items)) print(type(object()).__name__). Displayed result: 3 object. The final example bindings are items --> object 4 (list). object 4: [<object object>, <object object>, <object object>]

Follow the execution

Choose a different sample input, then follow every step through to the output. Before revealing it, predict what the program will display.

Execution workspace

Choose a sample and follow its execution. Guided simulation.

Code
Python
items = [object() for _ in range(3)]
print(len(items))
print(type(object()).__name__)
Live state

Top-level scope

items→Object 4
Object 4 · list[<object object>, <object object>, <object object>]
This step

The example has finished. Compare the final output with the values and references above.

Terminal
Output
3
object

What do you expect this program to print?

What does this example display?

items = [object() for _ in range(3)]
print(len(items))
print(type(object()).__name__)
What does this example display?
Choose one answer. You can try again.

Answer and explanation

3 object

Follow the printed values in order. The output is: 3 object

More examples and reference

Python object() Function

The object() function is the most basic built-in function in Python. It returns a featureless object that is the base for all new-style classes.

In Python, object is the top-most class in the class hierarchy. All classes inherit directly or indirectly from this base class.

Syntax

object()

Parameters:

  • None

Returns:

  • A new featureless object instance.

Example: Create a Blank Object

obj = object()
print(type(obj))
<class 'object'>

Why Use object()?

  • Used as a base class in custom class definitions.
  • Helps define immutable and minimal objects.
  • Essential when creating classes in modern Python (new-style classes).

Example: Inheriting from object

Although it's optional in Python 3, you can explicitly inherit from object to define a class:

class MyClass(object):
    pass

instance = MyClass()
print(isinstance(instance, object))
True

Use Case: Ensuring Consistent Inheritance

Explicitly using object helps ensure consistent method resolution order (MRO), especially in multiple inheritance scenarios.

Attributes of object()

Although featureless, object() still has some basic methods:

  • __str__()
  • __repr__()
  • __eq__()
  • __hash__()

Common Mistakes

  • Modifying the returned object from object() – You can't add attributes to it directly.
  • Confusing object() with instantiating a usable structure – It’s only meant as a base type.

Interview Tip

In interviews, understanding that all Python classes inherit from object is important. It affects how methods like __init__ and __str__ behave in inheritance.

Summary

  • object() creates a minimal base object.
  • It is the ancestor of all Python classes.
  • Mostly used for inheritance and class hierarchies.

Practice Problem

Create a custom class that inherits from object and adds a method to greet.

class Greeter(object):
    def greet(self):
        return "Hello from object!"

obj = Greeter()
print(obj.greet())
Hello from object!

This shows how even a basic class built from object can be extended for real use.

What to remember

Connect what you noticed in the example with the idea below.

Remember

object() constructs a basic object. Distinct live objects have different identities even when they share the same type.

Watch out for this idea

Every call to object() returns the same singleton object.

This is the misconception to avoid.

Reference checks are optional and do not count toward course progress.

    Reference library →