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
  Type hinting - return type based on parameter micseydel 2 116 Jan-14-2020, 01:20 AM
Last Post: micseydel
  Object of type set is not JSON serializable enigma619 5 558 Dec-19-2019, 03:30 PM
Last Post: enigma619
  type of object as a string Skaperen 1 160 Dec-02-2019, 08:01 AM
Last Post: midarq
  Object of type Scoreboard is not JSON serializable lsepolis123 9 2,775 Aug-13-2019, 11:22 AM
Last Post: lsepolis123
  class returns NoneType Object istemihan 0 268 Aug-12-2019, 11:47 AM
Last Post: istemihan
  Return a value when I equal an object from a class ihouses 4 377 Jul-10-2019, 02:44 AM
Last Post: SheeppOSU
  How to save a class object to a file? SheeppOSU 2 346 Jun-22-2019, 11:54 PM
Last Post: metulburr
  saving (in text or binary) an object under a defined class cai0824 3 491 May-12-2019, 08:55 AM
Last Post: snippsat
  Object type of Node to json bhojendra 4 688 Apr-28-2019, 01:36 PM
Last Post: bhojendra
  TypeError: object of type 'NoneType' has no len() - what do it mean? leviathan54 4 2,579 Apr-20-2019, 12:04 PM
Last Post: leviathan54

Forum Jump:

Users browsing this thread: 1 Guest(s)