- くだすれPython(超初心者用) その26 [転載禁止]©2ch.net
809 :デフォルトの名無しさん[sage]:2015/08/19(水) 03:02:58.44 ID:1cIU6vdw - >>803
elifをifに換えると上手く動かない例 test_result = 95 if test_result > 90: grade = 'A' elif test_result > 80: grade = 'B' elif test_result > 70: grade = 'C' elif test_result > 60: grade = 'D' else: grade = 'E' print('テストの点は', test_result, '成績は', grade)
| - くだすれPython(超初心者用) その26 [転載禁止]©2ch.net
820 :デフォルトの名無しさん[sage]:2015/08/19(水) 13:31:02.10 ID:1cIU6vdw - switch文よりパターンマッチの式が欲しい、下みたいなことlambda書かずにやりたい
result = match(10+3, [ lambda n: 'hoge' if n > 20 else ContinueMatch, lambda n: 'fuga' if n > 10 else ContinueMatch, lambda otherwise: 'moge'])
|
|