Understanding Object Type in Python

  • Topic: Python 
  • Thread starter Arman777
  • Start date
  • Tags Tags
    Python Type
6 replies · 2K views · last reply
Arman777
Insights Author
Gold Member
Messages
2,163
Reaction score
191
Table 4-1, Built-in objects preview: two columns, Object type and Example literals/creation, listing Numbers, Strings, Lists, Dictionaries, Tuples, Files, Sets, Other core types, Program unit types and Implementation-related types with Python literal examples.


As far as I know, there is no object type in python. How it's determined?

For instance, we know that 2 is an object and it belongs to the int class. Similarly, 2.1 is an object, and it belongs to the float class. From my research, I have learned that data type ##\equiv## class. Then what the heck is object type? Is it just a personal naming convention done by the author?
 
Arman777 said:
From my research, I have learned that data type = class. Then what the heck is object type?
In general, "type" to a much wider concept than "class". Put very short you could say "class" corresponds to "custom type", i.e. a type with custom semantics defined by the program as opposed being a built-in type in the language in question with a "fixed" syntax and semantics.

In Python3, the internal implementation of the "type" and "class" has been unified (I am not into the details of that), but that does not mean you should think of them as being the same concept when you write your own python program.
 
Arman777 said:
I see but is there way to reach them via python ? For instance I can reach the class (data type) via type(). Is there a way to reach object type (numeric, string etc,) via a command ?
Of course not. You can see from the manual that 'type' is a concept.
Python manual said:
The principal built-in types are numerics, sequences, mappings, classes, instances and exceptions.
How can a command return a concept?

In your defence, it doesn't help that the function to get the name of the class of an object is type, but if the language was completely logical they wouldn't have called it Python :biggrin:
 
Last edited:
  • Haha
Likes   Reactions: Vanadium 50
In the book it says numbers, string, list etc. However in the article it says Numeric, Sequence Types etc. Thats also strange
 
That's because they are concepts: 'numbers' and 'numeric types' are the same concept.