15.04.2013 Views

Core Python Programming (2nd Edition)

Core Python Programming (2nd Edition)

Core Python Programming (2nd Edition)

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Table 4.3. Standard Type Boolean Operators<br />

Operator Function<br />

not expr Logical NOT of expr (negation)<br />

expr1 and expr2 Logical AND of expr1 and expr2 (conjunction)<br />

expr1 orexpr2 Logical OR of expr1 and expr2 (disjunction)<br />

>>> x, y = 3.1415926536, -1024<br />

>>> x < 5.0<br />

True<br />

>>> not (x < 5.0)<br />

False<br />

>>> (x < 5.0) or (y > 2.718281828)<br />

True<br />

>>> (x < 5.0) and (y > 2.718281828)<br />

False<br />

>>> not (x is y)<br />

True<br />

Earlier, we introduced the notion that <strong>Python</strong> supports multiple comparisons within one expression.<br />

These expressions have an implicit and operator joining them together.<br />

>>> 3 < 4 < 7 # same as "( 3 < 4 ) and ( 4 < 7 )"<br />

True

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!