0

What is the exact difference between class and data types? For checking the data type in Python, we used type(). For example we have a boolean data type, this will display <class 'bool'> in the console. Are they the same thing?

Dj_c49
  • 11
  • 1
  • This is a clone of this thread [Same Question](https://stackoverflow.com/questions/35958961/class-vs-type-in-python) – Vaibhav Jain Jun 10 '23 at 19:19
  • 1
    They’re mostly the same thing. When you’re discussing types more abstractly (like in a static typechecking context) then the terms get less interchangeable — eg a “union type” refers to one of multiple classes, and a “generic type” is parameterized so it can refer to a class that’s used in a particular way, and “type variables” are variables that can refer to arbitrary other types within certain bounds. But if you talk about the type of a particular concrete object at runtime, yes, that’s always a particular class. – Samwise Jun 10 '23 at 19:24

1 Answers1

0

When you use the type() function in Python, it returns the data type of the object you pass to it. For example, if you use type(True), it will return <class 'bool'>, indicating that the data type of True is a boolean. In the case of built-in data types like booleans, type() actually returns the class that represents that data type. The bool class in Python represents boolean values. So, in a way, the data type and the class are connected. The class defines the data type and provides the implementation for working with objects of that type.

SHresTho12
  • 24
  • 6