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
  error in class: TypeError: 'str' object is not callable akbarza 2 418 Dec-30-2023, 04:35 PM
Last Post: deanhystad
  Use a class type in it MathisDELAGE 2 868 Jan-29-2023, 11:37 AM
Last Post: MathisDELAGE
  declaring object parameters with type JonWayn 2 851 Dec-13-2022, 07:46 PM
Last Post: JonWayn
  search a list or tuple for a specific type ot class Skaperen 8 1,829 Jul-22-2022, 10:29 PM
Last Post: Skaperen
Exclamation win32com: How to pass a reference object into a COM server class Alfalfa 3 4,768 Jul-26-2021, 06:25 PM
Last Post: Alfalfa
Star Type Error: 'in' object is not callable nman52 3 3,310 May-01-2021, 11:03 PM
Last Post: nman52
  Python generics: How to infer generic type from class attribute? Thoufak 0 2,753 Apr-25-2021, 09:31 AM
Last Post: Thoufak
  AttributeError class object has no attribute list object scttfnch 5 3,300 Feb-24-2021, 10:03 PM
Last Post: scttfnch
  Python Class and Object Parameters JoeDainton123 5 2,805 Sep-02-2020, 10:43 AM
Last Post: JoeDainton123
  TypeError: 'type' object is not subscriptable Stef 1 4,417 Aug-28-2020, 03:01 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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