LoginSignup
0
1

More than 1 year has passed since last update.

Pythonの判定(排他的論理和)

Posted at

pythonでの排他的論理和の判定

例えば、入力チェックをする際に、両方値が入っているもしくは、入っていない場合は不可で、
どちらか一方のみ値が入力されている状態を正とする場合のチェック処理

xor.py
# 入力データ(判定対象のデータ)
# data = {
#   "data1": "",
#   "data2": "test"
#}

# boolでキャスト(しなくてもよいが明示的にしてみた)
if bool(data["data1"]) != bool(data["data2"]):
    print("排他的")

上記のように!=を使えば排他的論理和の確認ができる。

0
1
0

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
0
1