开发者

What does the ** maths operator do in Python?

开发者 https://www.devze.com 2022-12-10 10:33 出处:网络
What does this mean in Python: sock.recvfrom(2**16) I know what sock is, and I get the gist of the recvfrom function, but what the heck is 2**16? Specifically, the two asterisk/double asterisk oper

What does this mean in Python:

sock.recvfrom(2**16)

I know what sock is, and I get the gist of the recvfrom function, but what the heck is 2**16? Specifically, the two asterisk/double asterisk operator?


(english keywords, because it'开发者_C百科s hard to search for this: times-times star-star asterisk-asterisk double-times double-star double-asterisk operator)


It is the power operator.

From the Python 3 docs:

The power operator has the same semantics as the built-in pow() function, when called with two arguments: it yields its left argument raised to the power of its right argument. The numeric arguments are first converted to a common type, and the result is of that type.

It is equivalent to 216 = 65536, or pow(2, 16)


http://docs.python.org/library/operator.html#mapping-operators-to-functions

a ** b  =  pow(a,b)


2 raised to the 16th power


I believe that's the power operator, such that 2**5 = 32.


It is the awesome power operator which like complex numbers is another thing you wonder why more programming languages don't have.

0

精彩评论

暂无评论...
验证码 换一张
取 消