plus/minus operator for python ±

前端 未结 7 592
遇见更好的自我
遇见更好的自我 2020-12-31 02:20

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

相关标签:
7条回答
  • 2020-12-31 03:07

    Instead of computing expressions like

    s1 = sqrt((125.0 + 10.0*sqrt(19)) / 366.0)
    s2 = sqrt((125.0 - 10.0*sqrt(19)) / 366.0)
    

    you could use

    r = 10.0*sqrt(19)
    s1, s2 = (sqrt((125.0 + i) / 366.0) for i in (r, -r))
    

    This is based on Nico's answer, but using a generator expression instead of NumPy

    0 讨论(0)
提交回复
热议问题