码迷,mamicode.com
首页 > 其他好文 > 详细

pow(x, y[, z])

时间:2017-04-26 15:44:35      阅读:292      评论:0      收藏:0      [点我收藏+]

标签:UI   utils   amp   dom   compute   org   arguments   ret   this   

w

 

https://docs.python.org/2/library/functions.html#pow

 

Return x to the power y; if z is present, return x to the power y, modulo z (computed more efficiently than pow(x, y) z). The two-argument form pow(x, y) is equivalent to using the power operator: x**y.

The arguments must have numeric types. With mixed operand types, the coercion rules for binary arithmetic operators apply. For int and long int operands, the result has the same type as the operands (after coercion) unless the second argument is negative; in that case, all arguments are converted to float and a float result is delivered. For example, 10**2 returns 100, but 10**-2 returns 0.01. (This last feature was added in Python 2.2. In Python 2.1 and before, if both arguments were of integer types and the second argument was negative, an exception was raised.) If the second argument is negative, the third argument must be omitted. If z is present, x and ymust be of integer types, and y must be non-negative. (This restriction was added in Python 2.2. In Python 2.1 and before, floating 3-argument pow() returned platform-dependent results depending on floating-point rounding accidents.)

 

 

# print ‘www‘
# print [w+ww for w in ‘abcd‘ for ww in ‘123‘]
# print [‘http://babynames.net/all/starts-with/%(az)s?page=%(page)i‘ %{‘az‘:az,‘page‘:page} for az in ‘abcdefghijklmnopqrst‘ for page in range(1,14,1)]



# import random
# def isprime(n, k=128):
#     if n < 2:
#         return False
#     for _ in range(k):
#         a = random.randrange(1, n)
#         if pow(a, n - 1, n) != 1:
#             return False
#             return True
# # w=isprime(44, k=128)
# # print w
# w=isprime(13, k=128)
# print w

print pow(11, 2, 2)
print pow(11, 2, 11)
print pow(11, 2, 100)

 

pow(x, y[, z])

标签:UI   utils   amp   dom   compute   org   arguments   ret   this   

原文地址:http://www.cnblogs.com/yuanjiangw/p/6768608.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!