条件式 (条件分岐演算子; 三項演算子)

def judge_high_and_low( x, correct_number ):
    return( "正解です" x == correct_number else \
                           ( "大きすぎます" if x > correct_number else \
                                                         "小さすぎます" )

λ式 (ラムダ式)

judge_high_and_low = \
    lambda x, correct_number: \
        "正解です" x == correct_number else \
                           ( "大きすぎます" if x > correct_number else \
                                                         "小さすぎます"

SoftEng: Python/Prog/Practice/Extended/02/EP_005a/AdvancedTopics (last edited 2018-10-29 04:45:34 by TadashiIijima)