기본문법
Python
1 2 3 4 | if True : print ( "code1" ) print ( "code2" ) print ( "code3" ) |
Ruby
1 2 3 4 5 | if true puts( "code1" ) puts( "code2" ) end puts( "code3" ) |
실행결과
1 2 3 | code1 code2 code3 |
조건문의 활용
Python
1 2 3 4 | input = 11 real = 11 if real = = input : print ( "Hello!" ) |
Ruby
1 2 3 4 5 | input = 11 real = 11 if real == input puts( "Hello!" ) end |
실행결과
1 | Hello! |
else
Python
1 2 3 4 5 6 | input = 11 real = 11 if real = = input : print ( "Hello!" ) else : print ( "Who are you?" ) |
Ruby
1 2 3 4 5 6 7 | input = 11 real = 11 if real == input puts( "Hello!" ) else puts( "Who are you?" ) end |
실행결과
1 | Hello! |
else if
Python
1 2 3 4 5 6 7 8 9 | input = 33 real_egoing = 11 real_k8805 = "ab" if real_egoing = = input : print ( "Hello!, egoing" ) elif real_k8805 = = input : print ( "Hello!, k8805" ) else : print ( "Who are you?" ) |
Ruby
1 2 3 4 5 6 7 8 9 10 | input = 33 real_egoing = 11 real_k8805 = "ab" if real_egoing == input puts( "Hello!, egoing" ) elsif real_k8805 == input puts( "Hello!, k8805" ) else puts( "Who are you?" ) end |
실행결과
1 | Who are you? |