Last answered:

28 Feb 2023

Posted on:

27 Feb 2023


Resolved: object not in stack class

Why is there not an object inside the parenthesis class stack()?

Best regards

1 answers ( 1 marked as helpful)
Posted on:

28 Feb 2023


Hey Arsalan,

Thank you for reaching out!

Writing the key word object in Stack(object) means you are inheriting everything from the object() class. Every time you create a class in Python, however, you are by default inheriting from the object() class. This implies that Stack() and Stack(object) perform identically and makes the object keyword redundant.

To prove this point, let me list all members defined in the Stack() using the dir() function:

In the list, we can find all methods and variables defined in the Stack() class, together with some additional members which came from the object() class. You can ensure that they indeed come from there by creating an instance of the object() class, call it my_object, and listing all its members:

You can compare both lists to ensure that all members of my_object are included in the new_stack object.

Hope this helps!

Kind regards,

365 Hristina

Submit an answer