**: exponentiation^: exclusive-or (bitwise)%: modulus//: divide with integral result (discard remainder)
**: exponentiation^: exclusive-or (bitwise)%: modulus//: divide with integral result (discard remainder)
You can find all of those operators in the Python language reference, though you'll have to scroll around a bit to find them all. As other answers have said:
- The
**operator does exponentiation.a ** bisaraised to thebpower. The same**symbol is also used in function argument and calling notations, with a different meaning (passing and receiving arbitrary keyword arguments). - The
^operator does a binary xor.a ^ bwill return a value with only the bits set inaor inbbut not both. This one is simple! - The
%operator is mostly to find the modulus of two integers.a % breturns the remainder after dividingabyb. Unlike the modulus operators in some other programming languages (such as C), in Python a modulus it will have the same sign asb, rather than the same sign asa. The same operator is also used for the "old" style of string formatting, soa % bcan return a string ifais a format string andbis a value (or tuple of values) which can be inserted intoa. - The
//operator does Python's version of integer division. Python's integer division is not exactly the same as the integer division offered by some other languages (like C), since it rounds towards negative infinity, rather than towards zero. Together with the modulus operator, you can say thata == (a // b)*b + (a % b). In Python 2, floor division is the default behavior when you divide two integers (using the normal division operator/). Since this can be unexpected (especially when you're not picky about what types of numbers you get as arguments to a function), Python 3 has changed to make "true" (floating point) division the norm for division that would be rounded off otherwise, and it will do "floor" division only when explicitly requested. (You can also get the new behavior in Python 2 by puttingfrom __future__ import divisionat the top of your files. I strongly recommend it!)
Can someone explain what //= mean in Python? def reverse_number(number): reversed_number = 0 while number > 0: reversed_number = reversed_number * 10 + number % 10 number //= 10 return reversed_number
print(reverse_number(9))
what is the purpose of number //= 10?
Thanks
What is ... meaning in python
What does ! Mean?
What exactly is "in" in Python?
What do () and [] and . Mean in python?
Videos
Hii, while i was coding a number guessing game, i saw the use of !
What does ! Mean?
for i in range(10):
print('Hello!')Can we refer to in as a membership operator here?
print('a' in 'apple')What exactly is "in"? A keyword, operator, or something else.
For example Print("hello world") Why do i put in the "()" Why doesnt a simple print hello world work? Whats the logic behind using the () What does it tell the compiler about the code?
Similarly. List[2] and append.list
How does the compiler see those instructions as?
Sorry if this question sounds noobish. I AM a noob
I found here:
def __str__(self):
return "color: " + self.__color + \
" and filled: " + str(self.__filled)
a quick snippet:
class Scanner():
def __init__(self) -> None:
pass
def scan(self):
pass
what does the -> mean, I started using vs code a few weeks ago, and vs code automatically adds the -> whenever I create a class.
should I just add my parameters for __init__ and not do anything for the -> None or should I remove it
In Python, the '|' operator is defined by default on integer types and set types.
If the two operands are integers, then it will perform a bitwise or, which is a mathematical operation.
If the two operands are set types, the '|' operator will return the union of two sets.
a = set([1,2,3])
b = set([2,3,4])
c = a|b # = set([1,2,3,4])
Additionally, authors may define operator behavior for custom types, so if something.property is a user-defined object, you should check that class definition for an __or__() method, which will then define the behavior in your code sample.
So, it's impossible to give you a precise answer without knowing the data types for the two operands, but usually it will be a bitwise or.
Bitwise OR