Understanding Object Type in Python

  • Python
  • Thread starter Arman777
  • Start date
  • #1
2,134
179
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?
 

Answers and Replies

  • #3
2,134
179
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 theres not but just wanted to ask.
 
  • #4
Filip Larsen
Gold Member
1,440
348
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.
 
  • #5
pbuk
Science Advisor
Gold Member
2,506
1,245
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
  • #6
2,134
179
In the book it says numbers, string, list etc. However in the article it says Numeric, Sequence Types etc. Thats also strange
 
  • #7
pbuk
Science Advisor
Gold Member
2,506
1,245
That's because they are concepts: 'numbers' and 'numeric types' are the same concept.
 

Related Threads on Understanding Object Type in Python

  • Last Post
Replies
23
Views
571
Replies
4
Views
2K
Replies
13
Views
502
Replies
13
Views
1K
Replies
16
Views
355
  • Last Post
Replies
4
Views
726
  • Last Post
Replies
11
Views
941
Replies
6
Views
5K
Replies
6
Views
3K
Replies
7
Views
1K
Top