Reputation: 1579
I've tried searching online for this question but because the word "object" is so common I get lots of unrelated results instead of what I'm looking for. I also looked through the official docs here: https://docs.python.org/3/tutorial/classes.html and didn't find any explanation for this. So please don't freak out when you read this question.
Question:
In Python while declaring a new class we extend the object class. For ex:
class SomeClass(object):
#eggs and ham etc
Here we notice that SomeClass
has a capital S because we are following camel case. However, the class that we are inheriting from - "object
" doesn't seem to follow this naming convention. Why is the object class in all lower case?
Upvotes: 9
Views: 5993
Reputation: 38217
https://www.python.org/dev/peps/pep-0008/#class-names says:
Class Names
Class names should normally use the CapWords convention.
The naming convention for functions may be used instead in cases where the interface is documented and used primarily as a callable.
Note that there is a separate convention for builtin names: most builtin names are single words (or two words run together), with the CapWords convention used only for exception names and builtin constants. [emphasis mine]
All other classes should use the CapWorlds convention. As list
, object
, etc are built-in names, they follow this separate convention.
(copied from my answer to If the convention in Python is to capitalize classes, why then is list() not capitalized? Is it not a class?)
Upvotes: 8
Reputation: 9863
If you go to the python interpreter and do this:
>>> object
<type 'object'>
You'll see object is a built-in type, the other built-in types in python are also lowercase type, int, bool, float, str, list, tuple, dict, ...
. For instance:
>>> type.__class__
<type 'type'>
>>> object.__class__
<type 'type'>
>>> int.__class__
<type 'type'>
>>> type.__class__
<type 'type'>
>>> int.__class__
<type 'type'>
>>> bool.__class__
<type 'type'>
>>> float.__class__
<type 'type'>
>>> str.__class__
<type 'type'>
>>> list.__class__
<type 'type'>
>>> tuple.__class__
<type 'type'>
>>> dict.__class__
<type 'type'>
So it makes sense they are not lowercase, that way is quite easy to distinguish them from the other type of classes
Upvotes: 3
Reputation: 31
The short and basic answer is, class is just a keyword used by the python interpreter to know when some thing needs to be seen as a class , like how you have "def" for defining a function. Its a keyword to describe what follows is all.
Upvotes: -6
Reputation: 599628
All Python's built-in types have lower case: int, str, unicode, float, bool, etc. The object type is just another one of these.
Upvotes: 11