What do these operators mean (** , ^ , %, //)?
**
: exponentiation^
: exclusive-or (bitwise)%
: modulus//
: divide with integral result (discard remainder)
^=, -= and += symbols in Python
As almost any modern language, Python has assignment operators
so they can use them every time you want to assign a value to a variable after doing some arithmetic or logical operation, both (assignment and operation) are expressed in a compact way in one statement...
Table from Tutorials Point:
Operator Description Example = Assigns values from right side operands to left side operand c = a + b assigns value of a + b into c += Add AND It adds right operand to the left operand and assign the result to left operand c += a is equivalent to c = c + a -= Subtract AND It subtracts right operand from the left operand and assign the result to left operand c -= a is equivalent to c = c - a *= Multiply AND It multiplies right operand with the left operand and assign the result to left operand c *= a is equivalent to c = c * a /= Divide AND It divides left operand with the right operand and assign the result to left operand c /= a is equivalent to c = c / a %= Modulus AND It takes modulus using two operands and assign the result to left operand c %= a is equivalent to c = c % a **= Exponent AND Performs exponential (power) calculation on operators and assign value to the left operand c **= a is equivalent to c = c ** a //= Floor Division It performs floor division on operators and assign value to the left operand c //= a is equivalent to c = c // a
What does - mean in Python function definitions?
It's a function annotation.
In more detail, Python 2.x has docstrings, which allow you to attach a metadata string to various types of object. This is amazingly handy, so Python 3 extends the feature by allowing you to attach metadata to functions describing their parameters and return values.
There's no preconceived use case, but the PEP suggests several. One very handy one is to allow you to annotate parameters with their expected types; it would then be easy to write a decorator that verifies the annotations or coerces the arguments to the right type. Another is to allow parameter-specific documentation instead of encoding it into the docstring.
What does `` mean in Python?
It means not equal to. It was taken from
ABC
(python's predecessor) see here:I believex < y, x <= y, x >= y, x > y, x = y, x <> y, 0 <= d < 10
Order tests (
<>
means 'not equals')ABC
took it from Pascal, a language Guido began programming with.It has now been removed in Python 3. Use
!=
instead. If you are CRAZY you can scrap!=
and allow only<>
in Py3K using this easter egg:>>> from __future__ import barry_as_FLUFL
>>> 1 != 2
File "<stdin>", line 1
1 != 2
^
SyntaxError: with Barry as BDFL, use '<>' instead of '!='
>>> 1 <> 2
TrueWhat Does mean in Python?
The
>>
operator in Python is a bitwise right-shift. If your number is 5, then its binary representation is 101. When right-shifted by 1, this becomes 10, or 2. It's basically dividing by 2 and rounding down if the result isn't exact.Your example is bitwise-complementing
c1
, then right-shifting the result by 1 bit, then masking off all but the 24 low-order bits.
Related Topics
Python and Operator on Two Boolean Lists - How
How to Group a Pandas Dataframe by a Defined Time Interval
How to Save Final Model Using Keras
Python Load JSON File with Utf-8 Bom Header
How to Increase Jupyter Notebook Memory Limit
Converting a List of Tuples into a Dict
Recursive List Comprehension in Python
How to Overlay Two Graphs in Seaborn
Meaning of Using Commas and Underscores with Python Assignment Operator
Is There an Platform Independent Equivalent of Os.Startfile()
A Good Way to Make Long Strings Wrap to Newline
Splitting a String by List of Indices
Getting Processor Information in Python
Errors While Building/Installing C Module for Python 2.7
Spark Dataframe: Computing Row-Wise Mean (Or Any Aggregate Operation)
Vectorized Numpy Linspace for Multiple Start and Stop Values
Opencv Python: Draw Minarearect ( Rotatedrect Not Implemented)