[英]How to raise to the power with a fraction in python
I'm looking to do the following in python:我希望在 python 中执行以下操作:
[0.12 x 1.616 x (100 x 0.019 x 40)^1/3] x 300 x 527.5
I can't work out how to raise to the power of a fraction.我不知道如何提高分数的力量。 I want the output to be decimal.
我希望 output 是十进制的。
(100 x 0.019 x 40)^1/3
To raise a number n to power p, you can use the power operator **
:要将数字 n 提高到 p 的幂,可以使用幂运算符
**
:
n ** p
You can use the math.pow
function:您可以使用
math.pow
function:
>>> import math
>>> math.pow(27, 1/3)
3.0
>>> help(math.pow)
Help on built-in function pow in module math:
pow(x, y, /)
Return x**y (x to the power of y).
Or simply the **
(exponent) operator:或者只是
**
(指数)运算符:
>>> 27 ** (1/3)
3.0
Also be careful of your order of operations:还要注意您的操作顺序:
>>> 27 ** 1/3 # same as: (27 ** 1) / 3
9.0
>>> 27 ** (1/3)
3.0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.