「Python」比較演算子を利用するサンプル

演算子
「x < y」、「x <= y」、「x > y」、「x >= y」、
「x == y」、「x != y」、「x is y」、「x is not y」
「x in y」、「x not in y」
結果:bool型(Ture, False)

pythonコード
1.関数compfunc()の定義

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
def compfunc(score):
if score > 90:
print('Rank A')
elif score > 80:
print('Rank B')
elif score > 60:
print('Rank C')
elif score == 60:
print('Rank D')
else:
print('Rank E')
def compfunc(score): if score > 90: print('Rank A') elif score > 80: print('Rank B') elif score > 60: print('Rank C') elif score == 60: print('Rank D') else: print('Rank E')
def compfunc(score):
    if score > 90:
        print('Rank A')
    elif score > 80:
        print('Rank B')
    elif score > 60:
        print('Rank C')
    elif score == 60:
        print('Rank D')
    else:
        print('Rank E')

2.関数compfunc()を呼び出します。
compfunc(92)
compfunc(83)
compfunc(63)
compfunc(60)
compfunc(59)
3.実行結果
Rank A
Rank B
Rank C
Rank D
Rank E

Python

Posted by arkgame