You are viewing a single comment's thread from:

RE: Data Type in Python

in #python7 years ago

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.

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. :)

Sort:  

Thanks for the more information on type. I will cover it when I will discuss about the OOP's concept in Python.

Coin Marketplace

STEEM 0.15
TRX 0.16
JST 0.028
BTC 67779.88
ETH 2396.01
USDT 1.00
SBD 2.32