I read the following python code:
a=2**b
I know several languages like c,c++,c#,java... i even googled ** operator without any results.
so what does 2**b means?
It is the exponentiation operator. In your example, a
will have the result of 2
to the b
th power.
Check out the last entry in the table in this section.
In that example ** does represent exponation. but **(and also * ) can be used as unpacking operators. for instance when using a list of variables of unknown length as args for a function. I'm new to programming and python so I have difficulty using this in an example. perhaps one of you more experienced users can demonstrate
**
can also be used as a function parameter to pass a variable number of keyword arguments to a function. Example:
def x(**kwargs):
for key, value in kwargs.items():
print "%s: %s" % (key, value)
x(y=2, z=3, a=1, b=2)
Prints:
y: 2
z: 3
a: 1
b: 2
It means 2^b in other languages. Or math.pow(2, 4) if you were using the math module.
See operator documentation here: http://docs.python.org/library/stdtypes.html#numeric-types-int-float-long-complex
^
as the xor operator.
This means to raise 2 to the power b.
See http://docs.python.org/library/stdtypes.html#numeric-types-int-float-long-complex
2^b
(but^
means XOR in Python, so**
is used for the power2**0.5
is 1.414 (=sqrt(2)
) and2**-0.5
is 0.707.**
is not uncommon these days.