what does the expression "~" mean?
Asked
Active
Viewed 55 times
-2

Jens
- 9
- 4
-
1what is the context? – balderman Dec 07 '21 at 17:10
-
please see https://stackoverflow.com/questions/8305199/the-tilde-operator-in-python/8305225#8305225 – bonfab Dec 07 '21 at 17:11
-
It is bitwise negation. – smac89 Dec 07 '21 at 17:11
-
`~` is the bitwise NOT Operator, `|` is the Bitwise OR operator, and `&` is the bitwise AND Operator. – 2pichar Dec 07 '21 at 17:11
-
1Code needs to be provided **as text**, not images. See [Why not upload images of code/errors when asking a question?](https://meta.stackoverflow.com/a/285557/14122) – Charles Duffy Dec 07 '21 at 17:11
-
Another good link on the topic: https://idownvotedbecau.se/imageofcode – Charles Duffy Dec 07 '21 at 17:12
-
1`~` isn't an expression, it's an *operator*. – martineau Dec 07 '21 at 17:14
-
@Tbaki no, `~` on a `list` will raise a TypeError – juanpa.arrivillaga Dec 07 '21 at 17:19
-
@juanpa.arrivillaga Wierd, it work for a list of boolean to filter a pandas dataFrame – Tbaki Dec 07 '21 at 17:21
-
@Tbaki no, it absolutely did not. You are talking about a `numpy.ndarray` or a `pandas.Series`, definitely not a `list` – juanpa.arrivillaga Dec 07 '21 at 17:33
-
@juanpa.arrivillaga yes you understood what i was refering to so it's okay – Tbaki Dec 07 '21 at 17:38
-
@Tbaki no, you should speak precisely. This is programming, precise language is important. `list` means something different from either of those, and it is important to understand those difference and not to use terminology inaccurately or ambiguously. – juanpa.arrivillaga Dec 07 '21 at 17:39
1 Answers
0
from the doc: https://docs.python.org/3/reference/expressions.html#unary-arithmetic-and-bitwise-operations
The unary
~
(invert) operator yields the bitwise inversion of its integer argument. The bitwise inversion of x is defined as-(x+1)
. It only applies to integral numbers or to custom objects that override the__invert__()
special method.

juanpa.arrivillaga
- 88,713
- 10
- 131
- 172

Daniele Caliari
- 158
- 1
- 11
-
1You may want to use this reference instead https://docs.python.org/3/reference/expressions.html#unary-arithmetic-and-bitwise-operations – Tbaki Dec 07 '21 at 17:14
-