# 条件式(三項演算子)の基本パターン x = 101 s = 'odd' if x % 2 else 'even' print(s) # odd # 条件式のネスト s = 'positive' if x > 0 else 'negative' if x < 0 else 'zero' print(s) # positive # 内包表記と条件式 l1 = [3, 4, 6, 0, 1] l2 = ['odd' if x % 2 else 'even' for x in l1] print(l2) # ['odd', 'even', 'even', 'even', 'odd'] # ラムダ式と条件式 l1 = [3, 4, 6, 0, 1] it = map(lambda x: 'odd' if x % 2 else 'even', l1) l2 = list(it) print(