Tools, FAQ, Tutorials:
'bool' Values are Objects
Are "bool" values objects in Python?
✍: FYIcenter.com
Yes, "bool" values are objects in Python.
In fact, all data values in Python are objects.
In Python, "bool" is defined as a sub class of the "int" object class with the following interesting properties, constructors, and methods:
bool.__doc__ - Property holding a short description of "bool" objects.
bool.__new__() - Constructor returning an "int" object. It can be invoked as bool(). For example:
>>> bool.__new__(bool, True) True >>> bool.__new__(bool, "True") True >>> bool("True") True
bool.__and__() - Instance method for the AND operation. For example:
>>> (True).__and__(False) False >>> True & False False
bool.bit_length() - Instance method inherited the "int" class, returning the number of bits used to store this Boolean value. For example:
>>> (True).bit_length() 1 >>> (False).bit_length() 0
You can use the dir(bool) function to see all members of the "bool" class:
>>> dir(bool) ['__abs__', '__add__', '__and__', '__bool__', '__ceil__', '__class__', '__delatt r__', '__dir__', '__divmod__', '__doc__', '__eq__', '__float__', '__floor__', '_ _floordiv__', '__format__', '__ge__', '__getattribute__', '__getnewargs__', '__g t__', '__hash__', '__index__', '__init__', '__init_subclass__', '__int__', '__in vert__', '__le__', '__lshift__', '__lt__', '__mod__', '__mul__', '__ne__', '__ne g__', '__new__', '__or__', '__pos__', '__pow__', '__radd__', '__rand__', '__rdiv mod__', '__reduce__', '__reduce_ex__', '__repr__', '__rfloordiv__', '__rlshift__ ', '__rmod__', '__rmul__', '__ror__', '__round__', '__rpow__', '__rrshift__', '_ _rshift__', '__rsub__', '__rtruediv__', '__rxor__', '__setattr__', '__sizeof__', '__str__', '__sub__', '__subclasshook__', '__truediv__', '__trunc__', '__xor__' , 'bit_length', 'conjugate', 'denominator', 'from_bytes', 'imag', 'numerator', ' real', 'to_bytes']
2017-09-12, 977👍, 0💬
Popular Posts:
How to use "link" command tool to link objet files? If you have object files previously compiled by ...
FYIcenter JSON Validator and Formatter is an online tool that checks for syntax errors of JSON text ...
How to create the Hello-3.0.epub package? I have all required files to create Hello-3.0.epub. To cre...
What is Azure API Management Developer Portal Admin? The Developer Portal Admin is an Azure Web port...
Where Can I get a copy of the RSS XML Schema? RSS XML Schema is an XML Schema that defines how an RS...