RE: Data Type in Python by labwork

View this thread on: d.buzz | hive.blog | peakd.com | ecency.com

Viewing a response to: @labwork/data-type-in-python

·@gama·
0.000 HBD
I'm giving you some extensions.

For booleans: True is an alias of 1 and False of 0. They area interchangeable for logical validations. Of course it will be treated differently sometimes in serialization (e.g. json).

For type checking, you also can check if that's an instance of a class, which is better for classes that has inheritance. I give you an example.

```python
class Animal: pass
class Dog(Animal): pass
mypet = Dog()
print(isinstance(mypet, Animal))
# True
print(isinstance(mypet, Dog))
# True
print(isinstance(mypet, int))
# False
```

Where "type(mypet) is Animal" will be False and "type(mypet) is Dog" will be True, because type() does not check the inheritance.

Keep doing tutorials. :)
👍 ,