What are the properties of ‘object’, the simplest and most basic class?

Question

What are the properties of ‘object’, the simplest and most basic class?

Answer

In Python, the object from which all classes inherit their most basic properties is called object. This allows us to customize everything about our new class, including how to initialize it, how to set descriptors, accepting arguments, and more.
For an in-depth view, take a look at the top answer of this StackOverflow post about the object we inherit from!

3 Likes

Why wasn’t this the first ever excercise for the class module? I felt this exercise has a better explanation of what objects are and throws off any confusion the first exercise brings when it asks to create a class to understand its syntax

2 Likes

the simplest and most basic class

In terms of pre-2015, JS did not have classes, proper, but the language implied a class structure. In truth, it’s only a way to conceptualize what it really is… A prototypal language.

The top of the Object.prototype chain is, null.

 > Object.prototype
<- {constructor: ƒ, __defineGetter__: ƒ, __defineSetter__: ƒ, hasOwnProperty: ƒ, __lookupGetter__: ƒ, …}
 > Object.prototype.prototype == null
<- true
 >

All objects inherit from Object.prototype, meaning all those methods and other properties are accessible in the context of any object instance, be it a boolean, string, number, array, plain object or custom object, or function.

The closest thing to an ES class, is a JS constructor. The difference is that any function can be a constructor, but a class requires an explicit class definition.

Earlier in this course, we were told that “Whilst … not a strict ‘requirement’ it is a widely adopted convention” to capitalise the first letter of a class. But the object class always has a lower case “o” in the tutorials. Why is that?

Can you furnish an example of this, please, and perhaps a link to the lesson?

For example:-

Learn Python 2: Introduction to Classes: Lessons 7 to 18

Learn Python 2: Classes : Lesson 1 - 7 and probably more

It’s only a style point I think, and I am new to Python, but I would have expected:-

class Car(Object)

rather than

class Car(object)

Python 2 has reached its end of life and should be laid to rest. That said, if we look at the builtins we see they are all lower case…

str
int
float
bool
list
dict

etc. As for, class Dog(object):, in Python 3 we no longer have to specify object as the class our custom class will inherit from. It inherits by default, now.

class Dog:

In writing our own class definitions we should still maintain the convention of capitalizing their name. It is helpful in identifying instances.

1 Like

I could not agree more. The previous exercise was jumbled confusion that this exercise now carefully explains a simple piece at a time.

2 Likes