Python Understanding Object Type in Python

  • Thread starter Thread starter Arman777
  • Start date Start date
  • Tags Tags
    Python Type
AI Thread Summary
The discussion revolves around the concept of object types in Python, clarifying the distinction between "type" and "class." It emphasizes that while every object in Python is an instance of a class, the term "object type" is more abstract and encompasses broader categories like numerics, sequences, and mappings. Participants highlight that "type" refers to a built-in concept rather than a specific command that can be accessed in Python. The confusion arises from the terminology used in documentation, where terms like "numbers" and "numeric types" are used interchangeably, reflecting the conceptual nature of these classifications. Overall, the conversation underscores the importance of understanding these distinctions for effective programming in Python.
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?
 
Technology news on Phys.org
  • Like
Likes Vanadium 50 and Arman777
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 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.
 

Similar threads

Back
Top