Understanding Object Type in Python

  • Context: Python 
  • Thread starter Thread starter Arman777
  • Start date Start date
  • Tags Tags
    Python Type
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
6 replies · 2K views
Arman777
Insights Author
Gold Member
Messages
2,163
Reaction score
191
Adsız.png


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?
 
Physics news on Phys.org
pbuk said:
No, you can check this by RTFM: https://docs.python.org/3/library/stdtypes.html.
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 ?

I think there's not but just wanted to ask.
 
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