「python」三項演算子のサンプル
書式
変数名=値1 if x < y else 値2
使用例
# coding: utf-8
#!/usr/bin/python3
x = 11
y = 22
res=66 if x < y else 10
print("三項演算子の結果")
print(res)
# coding: utf-8
#!/usr/bin/python3
x = 11
y = 22
res=66 if x < y else 10
print("三項演算子の結果")
print(res)
# coding: utf-8 #!/usr/bin/python3 x = 11 y = 22 res=66 if x < y else 10 print("三項演算子の結果") print(res)
実行結果
>python test.py
三項演算子の結果
66