Pro Python 3 by J. Burton Browning & Marty Alchin

Pro Python 3 by J. Burton Browning & Marty Alchin

Author:J. Burton Browning & Marty Alchin
Language: eng
Format: epub
ISBN: 9781484243855
Publisher: Apress

Basic Operations

Even though there are a wide variety of object types available in Python, most of them share a common set of operations. These are considered to be something of a core feature set, representing some of the most common high-level aspects of object manipulation, many of which are just as applicable to simple numbers as they are to many other objects.

One of the simplest and most common needs in all of programming, Python included, is to evaluate an expression to a Boolean value so that it can be used to make simple decisions. Typically this is used in if blocks, but these decisions also come into play when using while, and Boolean operations such as and and or. When Python encounters one of these situations, it relies on the behavior of the __bool__() method to determine the Boolean equivalent of an object.

The __bool__() method , if implemented, accepts just the usual self and must return either True or False. This allows any object to determine whether it should be considered to be true or false in a given expression, using whatever methods or attributes are appropriate:


Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.