Skip to Main Content
Python Programming On Win32
book

Python Programming On Win32

by Andy Robinson, Mark Hammond
January 2000
Intermediate to advanced content levelIntermediate to advanced
672 pages
21h 46m
English
O'Reilly Media, Inc.
Content preview from Python Programming On Win32

Truth Value Testing

Any object can be tested for truth value, to use in an if or while condition or as operand of the boolean operations below. The following values are considered false:

  • None

  • Zero of any numeric type, e.g., 0, 0L, 0.0

  • Any empty sequence, e.g., ‘ ’, (), []

  • Any empty mapping, e.g., {}

  • Instances of user-defined classes, if the class defines a __nonzero__() or __len__() method, when that method returns zero

All other values are considered true, so objects of many types are always true.

Operations and built-in functions that have a boolean result always return for false and 1 for true, unless otherwise stated. Important exceptions are the boolean operations or and and, which always return one of their operands.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Qt5 Python GUI Programming Cookbook

Qt5 Python GUI Programming Cookbook

B.M. Harwani

Publisher Resources

ISBN: 1565926218Supplemental ContentErrata Page