12.07.2015 Views

Is Python a

Is Python a

Is Python a

SHOW MORE
SHOW LESS
  • No tags were found...

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

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

Because of this customization, as of <strong>Python</strong> 2.3, the output of Boolean expressionstyped at the interactive prompt prints as the words True and False instead of theolder 1 and 0. In addition, Booleans make truth values more explicit. For instance, aninfinite loop can now be coded as while True: instead of the less intuitive while 1:.Similarly, flags can be initialized more clearly with flag = False.Again, though, for all other practical purposes, you can treat True and False asthough they are predefined variables set to integer 1 and 0. Most programmers werepreassigning True and False to 1 and 0 anyway, so the new type simply makes this astandard technique. Its implementation can lead to curious results, though—becauseTrue is just the integer 1 with a custom display format, True + 3 yields 4 in <strong>Python</strong>!We’ll revisit Booleans in Chapter 9 (to define <strong>Python</strong>’s notion of truth) and again inChapter 12 (to see how Boolean operators like and and or work).Third-Party ExtensionsBeyond <strong>Python</strong>’s own numeric types, you’ll find various third-party open sourceadd-ons that provide even more exotic numeric tools. Types such as rational numbers,vectors, and matrixes can be obtained on the Web; do a search for more details.Chapter SummaryThis chapter has taken a tour of <strong>Python</strong>’s numeric object types and the operationswe can apply to them. Along the way, we met the standard integer and floating-pointtypes, as well as some more exotic and less commonly used types such as complexnumbers and the decimal type. We also explored <strong>Python</strong>’s expression syntax, typeconversions, bitwise operations, and various literal forms for coding numbers inscripts.Later in this part of the book, I’ll fill in some details about the next object type, thestring. In the next chapter, however, we’ll take some time to explore the mechanicsof variable assignment in more detail than we have here. This turns out to be perhapsthe most fundamental idea in <strong>Python</strong>, so you should read through the nextchapter before moving on. First, though, take the usual chapter quiz.110 | Chapter 5: Numbers

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

Saved successfully!

Ooh no, something went wrong!