Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Object and type class
#1
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:
print(isinstance(list,object))
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
Reply
#2
Have a look here how isinstance() works
Reply
#3
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))
Output:
True False
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Return a string or byte object from Enum class? Calab 5 1,847 May-14-2025, 05:21 PM
Last Post: snippsat
  Python class members based on a type value voidtrance 7 2,456 Apr-11-2025, 10:10 PM
Last Post: deanhystad
  type object 'man' has no attribute 'centerX' Tempo 7 2,260 Mar-07-2025, 03:47 AM
Last Post: deanhystad
  Printing out incidence values for Class Object SquderDragon 3 1,856 Apr-01-2024, 07:52 AM
Last Post: SquderDragon
  error in class: TypeError: 'str' object is not callable akbarza 2 2,848 Dec-30-2023, 04:35 PM
Last Post: deanhystad
  Use a class type in it MathisDELAGE 2 2,299 Jan-29-2023, 11:37 AM
Last Post: MathisDELAGE
  declaring object parameters with type JonWayn 2 2,084 Dec-13-2022, 07:46 PM
Last Post: JonWayn
  search a list or tuple for a specific type ot class Skaperen 8 4,666 Jul-22-2022, 10:29 PM
Last Post: Skaperen
Exclamation win32com: How to pass a reference object into a COM server class Alfalfa 3 8,041 Jul-26-2021, 06:25 PM
Last Post: Alfalfa
Star Type Error: 'in' object is not callable nman52 3 5,279 May-01-2021, 11:03 PM
Last Post: nman52

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.