Numeric types

The two numeric types in Python that are most useful for analytics are integers and floating-point numbers. To convert to these types, you can use the int() and float() functions, respectively. The most common operations on numbers are supported with the usual operators: +, -, *, /, <, and >. Modules containing special methods for numeric types that are particularly useful for analytics include math and random. More information on numeric types is available in the online Python documentation (see the link in the previous section).

Note that with some Python versions, dividing two integers using the / operator performs floor division (with the numbers after the decimal place omitted); for example, 10/4 would equal 2, not 2.5. This is a stealthy yet egregious error that can throw off numerical calculations. However, with the version of Python we are using in this book, we don't need to worry about this error.

The Boolean type is a special integer type that can be used to represent the True and False values. To convert an integer to a Boolean type, you can use the bool() function. A zero gets converted to False; any other integer would get converted to True. Boolean variables behave like 1 (True) and 0 (False), except that they return True and False, respectively, when converted to strings.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset