「Python」論理演算子の論理積(and)を利用する方法

2020年12月16日

書式
if (条件式1) and (条件式2)
サンプルコード

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

cftX = 10
cftY = 10

if (cftX == 10) and (cftY == 10):
      print("result1: ","AAA") 
else:
      print("result2: ","BB")

if cftX == 10 == cftY:
      print("result3: ","CC")
else:
      print("result4: ","DD")

実行結果
>python test.py
result1: AAA
result3: CC

Python

Posted by arkgame