Understanding Object Type in Python

  • Context: Python 
  • Thread starter Thread starter Arman777
  • Start date Start date
  • Tags Tags
    Python Type
Click For Summary

Discussion Overview

The discussion revolves around the concept of "object type" in Python, exploring its definition, relationship to classes, and how it is represented within the language. Participants examine whether "object type" is merely a naming convention and seek clarification on how to access these types programmatically.

Discussion Character

  • Conceptual clarification
  • Debate/contested

Main Points Raised

  • One participant questions the existence of an "object type" in Python, suggesting that data type equates to class.
  • Another participant asserts that "type" encompasses a broader concept than "class," indicating that classes represent custom types while built-in types have fixed semantics.
  • A participant inquires about accessing object types programmatically, noting that while the class can be accessed via the type() function, it is unclear if object types can be retrieved similarly.
  • One response emphasizes that "type" is a concept and cannot be returned by a command, listing principal built-in types such as numerics and sequences.
  • There is a mention of differing terminology in a book versus an article, with a participant expressing confusion over the terms used for types.
  • Another participant clarifies that terms like 'numbers' and 'numeric types' refer to the same underlying concept.

Areas of Agreement / Disagreement

Participants express differing views on the definition and accessibility of "object type," with no consensus reached on whether it is a valid concept or merely a naming convention.

Contextual Notes

Participants highlight potential confusion arising from terminology differences in various sources, which may affect understanding of the concepts discussed.

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   Reactions: 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   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.
 

Similar threads

  • · Replies 10 ·
Replies
10
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 10 ·
Replies
10
Views
6K
  • · Replies 25 ·
Replies
25
Views
6K
  • · Replies 23 ·
Replies
23
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
Replies
3
Views
1K
Replies
24
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K