Home > Article > Backend Development > How to use python pow function
The function of the pow function in python is to calculate the y power of x. This article will take you through the usage of the pow() function in Python. Interested friends can find out.
The following is the syntax of the math module pow() method:
import math math.pow( x, y )
Built-in pow() method
pow(x, y[, z])
Function It is to calculate the yth power of The method is called directly. The built-in method will treat the parameter as an integer, while the math module will convert the parameter into a float.
Parameters: x -- Numeric expression. y – Numeric expression. z – Numeric expression.
Return value: Return the value of xy (x to the power of y).
The following shows an example of using the pow() method:
1. Use in the command line
1 , pow(x,y): This represents the y power of x.
>>> pow(2,4) 16 >>>
2. pow(x,y,z): This is the remainder after dividing x to the yth power by z
>>> pow(2,4,5) 1 >>>
2. Use in IDE
#!/usr/bin/python # -*- coding: UTF-8 -*- import math # 导入 math 模块 print "math.pow(100, 2) : ", math.pow(100, 2) # 使用内置,查看输出结果区别 print "pow(100, 2) : ", pow(100, 2) print "math.pow(100, -2) : ", math.pow(100, -2) print "math.pow(2, 4) : ", math.pow(2, 4) print "math.pow(3, 0) : ", math.pow(3, 0)
The above is the detailed content of How to use python pow function. For more information, please follow other related articles on the PHP Chinese website!