Isn't ~ a Python operator? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

Isn't ~ a Python operator?

My understanding is that ~ ("tilde") is the bitwise negation operator in Python. However, a longstanding Python challenge question implies that it is not. Am I missing something here?

14th Dec 2017, 5:29 AM
Eric Blinkidu
Eric Blinkidu - avatar
3 Answers
+ 7
~x returns the bitwise complement of x, i.e. the number you get by switching each 1 for a 0 and each 0 for a 1. This is the same as -x - 1.
14th Dec 2017, 6:54 AM
David Ashton
David Ashton - avatar
+ 4
The quiz in question asks you to check off which of a list of four items are valid Python operators. If you check off ~, you get it wrong. I have reported it as a wrong answer.
14th Dec 2017, 10:25 PM
Eric Blinkidu
Eric Blinkidu - avatar