Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the ** maths operator do in Python?

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's hard to search for this: times-times star-star asterisk-asterisk double-times double-star double-asterisk operator)

like image 215
rich johnson Avatar asked Nov 05 '09 19:11

rich johnson


People also ask

What is * operator used in Python?

Multiplication Operator: In Python, the multiplication operator is *. Furthermore, its use takes place to find the product of 2 values.

How does the * operator work among strings and numbers?

The * operator also works on strings. It performs repetition. For example, 'Fun'*3 is 'FunFunFun' . One of the operands has to be a string and the other has to be an integer.


1 Answers

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)

like image 193
rossoft Avatar answered Oct 05 '22 20:10

rossoft