I am looking for a way to do a plus/minus operation in python 2 or 3. I do not know the command or operator, and I cannot find a command or operator to do this.
Am I missing something?
In Python, to print the plus or minus symbol, you can use the unicode for the plus or minus sign '\u00B1'.
Definition of plus/minus sign : the sign ± used to indicate a quantity (such as 2 in "the square root of 4 is ±2") taking on both an algebraically positive value and its negative and to indicate a plus or minus quantity (such as 4 in "the population age was 30 ± 4 years") — called also plus/minus symbol.
The == operator compares the value or equality of two objects, whereas the Python is operator checks whether two variables point to the same object in memory. In the vast majority of cases, this means you should use the equality operators == and != , except when you're comparing to None .
Power (exponent) operator The operator that can be used to perform the exponent arithmetic in Python is ** . Given two real number operands, one on each side of the operator, it performs the exponential calculation ( 2**5 translates to 2*2*2*2*2 ).
If you are looking to print the ± symbol, just use:
print(u"\u00B1")
Another possibility: uncertainties is a module for doing calculations with error tolerances, ie
(2.1 +/- 0.05) + (0.6 +/- 0.05) # => (2.7 +/- 0.1)
which would be written as
from uncertainties import ufloat ufloat(2.1, 0.05) + ufloat(0.6, 0.05)
Edit: I was getting some odd results, and after a bit more playing with this I figured out why: the specified error is not a tolerance (hard additive limits as in engineering blueprints) but a standard-deviation value - which is why the above calculation results in
ufloat(2.7, 0.07071) # not 0.1 as I expected!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With