operators

What is the '@=' symbol for in Python?

What is the '@=' symbol for in Python? Question: I know @ is for decorators, but what is @= for in Python? Is it just reservation for some future idea? This is just one of my many questions while reading tokenizer.py. Asked By: Octavia Togami || Source Answers: From the documentation: The @ (at) operator …

Total answers: 3

Multiplying without the multiplication operator in python

Multiplying without the multiplication operator in python Question: How do I write a python script that multiplies x * y without using the multiplication operator? I know that basically you should have: def multi(): x = raw_input(‘x is: ‘) y = raw_input(‘y is: ‘) z = #(x + x) y times return z multi() Asked …

Total answers: 5

Vertical bar in Python bitwise assignment operator

Vertical bar in Python bitwise assignment operator Question: There is a code and in class’ method there is a line: object.attribute |= variable I can’t understand what it means. I didn’t find (|=) in the list of basic Python operators. Asked By: Olga || Source Answers: That is a bitwise or with assignment. It is …

Total answers: 4

Python: and/or operators strange behavior

Python: and/or operators strange behavior Question: I know that the AND operator has precedence over the OR operator. I also believe that like in C/CPP the associativity of these operators is from left to right (although it doesn’t seem to be crucial for my question). I run the following code in Python 2.7.1: Case 1: …

Total answers: 2

New operators in Python

New operators in Python Question: We can define intrinsic operators of Python as stated here. Just for curiosity, can we define new operators like $ or ***? (If so, then we can define ternary condition operators or rotate operators.) Asked By: hola || Source Answers: No, you can’t define new operators in Python. Answered By: …

Total answers: 4

Is there a short-hand for nth root of x in Python?

Is there a short-hand for nth root of x in Python? Question: In maths, if I wish to calculate 3 to the power of 2 then no symbol is required, but I write the 2 small: 3². In Python this operation seems to be represented by the ** syntax. >>> 3**2 9 If I want …

Total answers: 9

'is' operator behaves differently when comparing strings with spaces

'is' operator behaves differently when comparing strings with spaces Question: I’ve started learning Python (python 3.3) and I was trying out the is operator. I tried this: >>> b = ‘is it the space?’ >>> a = ‘is it the space?’ >>> a is b False >>> c = ‘isitthespace’ >>> d = ‘isitthespace’ >>> …

Total answers: 6

What does `<>` mean in Python?

What does `<>` mean in Python? Question: I’m trying to use in Python 3.3 an old library (dating from 2003!). When I import it, Python throws me an error because there are <> signs in the source file, e.g.: if (cnum < 1000 and nnum <> 1000 and ntext[-1] <> “s”: … I guess it’s …

Total answers: 5

How can I obtain the element-wise logical NOT of a pandas Series?

How can I obtain the element-wise logical NOT of a pandas Series? Question: I have a pandas Series object containing boolean values. How can I get a series containing the logical NOT of each value? For example, consider a series containing: True True True False The series I’d like to get would contain: False False …

Total answers: 6

When is "i += x" different from "i = i + x" in Python?

When is "i += x" different from "i = i + x" in Python? Question: I was told that += can have different effects than the standard notation of i = i +. Is there a case in which i += 1 would be different from i = i + 1? Asked By: MarJamRob || …

Total answers: 3