LoginSignup
2
2

More than 5 years have passed since last update.

Pythonの~xって何?

Posted at

Pythonのソースコードを見ていたとき、謎の一文を見つけてしまったのでメモ

~を使うとどうなるの

簡単な式で表せます。

~x


$$-(x+1)$$
です。

~1  # -2
~100 # -101

~の正体

どうやらビット演算子の一つらしいです。

最後に

Googleで「Python ~」で検索しても~は無視されちゃって大変でした…

記号を無視しない設定を用意してほしいです。(すでに用意されてる可能性大ですが)

2
2
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2