What Does '<>' Mean in Python

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:




















































OperatorDescriptionExample
=Assigns values from right side operands to left side operandc = a + b assigns value of a + b into c
+= Add ANDIt adds right operand to the left operand and assign the result to left operandc += a is equivalent to c = c + a
-= Subtract ANDIt subtracts right operand from the left operand and assign the result to left operandc -= a is equivalent to c = c - a
*= Multiply ANDIt multiplies right operand with the left operand and assign the result to left operandc *= a is equivalent to c = c * a
/= Divide ANDIt divides left operand with the right operand and assign the result to left operandc /= a is equivalent to c = c / a
%= Modulus ANDIt takes modulus using two operands and assign the result to left operandc %= a is equivalent to c = c % a
**= Exponent ANDPerforms exponential (power) calculation on operators and assign value to the left operandc **= a is equivalent to c = c ** a
//= Floor DivisionIt performs floor division on operators and assign value to the left operandc //= 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:

x < y, x <= y, x >= y, x > y, x = y, x <> y, 0 <= d < 10

Order tests (<> means 'not equals')

I believe 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
True

What 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



Leave a reply



Submit