今天就学习课程吧!
今天就开通帐号,24,600 门业界名师课程任您挑!
Truth value testing
- [Narrator] In Python, any object can be tested for Boolean truth value. So, let's take a few moments now to learn about how that works. In general, any object is considered to be equivalent to Boolean true, unless it's class defines a Bool method that returns false, or has a len method that returns a zero length. So, let's look first at the built-in objects that evaluate to false. There are two constants which are defined to evaluate to false, the false Boolean constant itself, of course, and the none constant, which you may have seen represented in other languages as null. Any of the built-in numeric types that evaluate to zero are also considered to be false. For example, the integer value zero, the floating-point value 0.0, and the complex value type of 0j are all false values. In addition, the decimal object, when given a value of zero, and the fractional object, when it has a numerator of zero, are also false. Next are empty sets and sequences. And you can see the examples…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。