python官方题解--数值的整数次方
数值的整数次方
http://www.nowcoder.com/questionTerminal/1a834e5e3e1a4b7ba251417554e07c00
需要考虑的几种情况在代码中标明
class Solution: def Power(self, base, exponent): # write code here temp = base # 0的0次方和0的负数次方无意义 if base == 0.0 and exponent <= 0: return None #0的次方为0 if base == 0.0 : return 0 #除0以外的任何数的0次方都为0 if exponent == 0: return 1 #负数次方时 if exponent < 0: for i in range(-exponent-1): base *= temp return 1.0 / base else: #正数次方时 for i in range(exponent-1): base *= temp return base