4
How to best expose in Python?
I must use the operator **
or math.pow
?
Example math.pow
:
> math.pow(3, 4);
#Imprime: 81.0
Example with double asterisk?
> 3 ** 4
#Imprime : 81
What I must take into account when using them?
4
How to best expose in Python?
I must use the operator **
or math.pow
?
Example math.pow
:
> math.pow(3, 4);
#Imprime: 81.0
Example with double asterisk?
> 3 ** 4
#Imprime : 81
What I must take into account when using them?
5
The operator **
is usually faster than math.pow()
. He calls the native function pow
, which, by the way, accepts a module argument. Usually it is better for integers.
math.pow()
always returns a float
. In this case, when the guys are float
, math.pow()
is faster.
Browser other questions tagged python
You are not signed in. Login or sign up in order to post.
But if we want to enter in this "security of types" with the number
3
for example, wanting him to returnfloat
, we could just do 3.0 ** 3, right?– Wallace Maxters
Yes, because if there’s even one
float
involved in the operation, the result is afloat
also.– Leonel Sanches da Silva