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
  Python class members based on a type value voidtrance 7 1,229 Apr-11-2025, 10:10 PM
Last Post: deanhystad
  type object 'man' has no attribute 'centerX' Tempo 7 842 Mar-07-2025, 03:47 AM
Last Post: deanhystad
  Printing out incidence values for Class Object SquderDragon 3 1,248 Apr-01-2024, 07:52 AM
Last Post: SquderDragon
  error in class: TypeError: 'str' object is not callable akbarza 2 1,745 Dec-30-2023, 04:35 PM
Last Post: deanhystad
  Use a class type in it MathisDELAGE 2 1,768 Jan-29-2023, 11:37 AM
Last Post: MathisDELAGE
  declaring object parameters with type JonWayn 2 1,655 Dec-13-2022, 07:46 PM
Last Post: JonWayn
  search a list or tuple for a specific type ot class Skaperen 8 3,602 Jul-22-2022, 10:29 PM
Last Post: Skaperen
Exclamation win32com: How to pass a reference object into a COM server class Alfalfa 3 6,717 Jul-26-2021, 06:25 PM
Last Post: Alfalfa
Star Type Error: 'in' object is not callable nman52 3 4,520 May-01-2021, 11:03 PM
Last Post: nman52
  Python generics: How to infer generic type from class attribute? Thoufak 0 3,776 Apr-25-2021, 09:31 AM
Last Post: Thoufak

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020