Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Object and type class
Hi, i'm a bit confused about type class and object class. I know that every normal class and built-in type are instance of type class and inherit from object class (is that correct? please correct me if i'm wrong). But when i try this:
It printed: True

Why is that? I thought object is the base class of list not the class which list was created from !. Can anybody show me the relationship between object class, type class, normal class, built-in type like list and string
Have a look here how isinstance() works
All objects inherit from object. Testing objects against object should be always True, even if you check type against object.

The normal use is:
my_object = [1, 2, 3]
print(isinstance(my_object, list))
print(isinstance(my_object, tuple))
True False
My code examples are always for Python >=3.6.0
Almost dead, but too lazy to die:
All humans together. We don't need politicians!

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Hi, need help with class, object Houston222 1 140 Apr-04-2020, 01:55 PM
Last Post: buran
  AttributeError: type object 'FunctionNode' has no attribute '_TestValidateFuncLabel__ binhduonggttn 0 243 Feb-19-2020, 11:29 AM
Last Post: binhduonggttn
  Type hinting - return type based on parameter micseydel 2 226 Jan-14-2020, 01:20 AM
Last Post: micseydel
  Object of type set is not JSON serializable enigma619 5 2,622 Dec-19-2019, 03:30 PM
Last Post: enigma619
  type of object as a string Skaperen 1 284 Dec-02-2019, 08:01 AM
Last Post: midarq
  Object of type Scoreboard is not JSON serializable lsepolis123 9 3,836 Aug-13-2019, 11:22 AM
Last Post: lsepolis123
  class returns NoneType Object istemihan 0 401 Aug-12-2019, 11:47 AM
Last Post: istemihan
  Return a value when I equal an object from a class ihouses 4 457 Jul-10-2019, 02:44 AM
Last Post: SheeppOSU
  How to save a class object to a file? SheeppOSU 2 543 Jun-22-2019, 11:54 PM
Last Post: metulburr
  saving (in text or binary) an object under a defined class cai0824 3 597 May-12-2019, 08:55 AM
Last Post: snippsat

Forum Jump:

Users browsing this thread: 1 Guest(s)