「python」三項演算子のサンプル

書式
変数名=値1 if x < y else 値2
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# 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

Python

Posted by arkgame