首页 > 代码库 > pow(x, y[, z])

pow(x, y[, z])

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])