Skip to playerSkip to main content
🚀 Python Tip You NEED to Know! 🐍
type() vs isinstance() — which one should you use? 🤔

📌 type() → Checks the exact type
📌 isinstance() → Checks type + subclasses

📌 Follow us for ❤ @nareshitech

#PythonTips #LearnPython #ProgrammingTips #PythonDeveloper

Category

📚
Learning
Transcript
00:00So what is the difference between type function and is instance function in Python?
00:04So type function in Python returns a type of object.
00:08Type function returns the name of the class to which that object belongs to.
00:13It returns a class name.
00:14If I am passing type of any object, it returns that object is of which class type.
00:20It returns a class name.
00:21But when it comes to the is instance, is instance function returns a boolean value that can be either true or false.
00:28It is to examine is it an object is belongs to a specific type.
00:33Is instance takes object name and class list.
00:36It is nothing but class information.
00:38Is it that object belongs to one type or more than one type?
00:42It is belongs to any one of the types given inside is instance list.
00:46It returns a true.
00:47Otherwise, it returns false.
00:49Is instance not only verifies the same class.
00:52It is also verifies is it this object is a subclass of that class.
00:56If it is even subclass of that class, it returns true.
01:00Otherwise, it returns false.
01:02So type is just return the type which is nothing but class name.
01:06But is instance returns a boolean value that can be either true or false.
01:12I hope you understood the difference between is instance and type function.
01:17Thanks for watching it.
Be the first to comment
Add your comment

Recommended