「Python」論理演算子の否定(not) を使う方法

2020年12月16日

構文
if (not 条件表現式)
サンプルコード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# coding: utf-8
#!/usr/bin/python3
cftX = 8
cftY = 9
if (not cftX == 10):
print("result1: ","not 10 AAA")
if (not cftY == 9):
print("result2: ","not 9 BBB")
else:
print("result3: ","is 9 CCC")
# coding: utf-8 #!/usr/bin/python3 cftX = 8 cftY = 9 if (not cftX == 10): print("result1: ","not 10 AAA") if (not cftY == 9): print("result2: ","not 9 BBB") else: print("result3: ","is 9 CCC")
# coding: utf-8
#!/usr/bin/python3

cftX = 8
cftY = 9

if (not cftX == 10):
      print("result1: ","not 10 AAA") 

if (not cftY == 9):
      print("result2: ","not 9 BBB")
else:
      print("result3: ","is 9 CCC")

実行結果
>python test.py
result1: not 10 AAA
result3: is 9 CCC

Python

Posted by arkgame