Working With Numbers in Python

Last modified: 
Friday, May 1st, 2015
Topics: 
Python

Overview

Some notes on working with numbers in python.

Exponents

# Exponents
print 2 ** 3 # 2^3 = 8
print 10 ** 10 # 10^10 = 10000000000
print 3 ** 101 # 3^101 = 1546132562196033993109383389296863818106322566003 (Python 2.7)

Precision of Repr As-Code Versus String

The value of 3.1415 * 9 is returned with extended precision (as seen from a terminal).

>>> 3.1415 * 9 
28.273500000000002

This format is called repr as-code.

The string value when passed through print is truncated.

>>> print 3.1415 * 9
28.2735


The operator of this site makes no claims, promises, or guarantees of the accuracy, completeness, originality, uniqueness, or even general adequacy of the contents herein and expressly disclaims liability for errors and omissions in the contents of this website.