반응형
Python :
if True:
print("code1")
print("code2")
print("code3")
Ruby :
if true
puts("code1")
puts("code2")
end
puts("code3")
Output :
code1
code2
code3
알게 된 내용 :
1. 파이썬은 Tab으로 조건문의 끝을 구분짓고, Ruby는 end 구문으로 명시적으로 조건문 끝을 구분짓는다.
2. 파이썬의 boolean 값은 True, False이며 루비의 boolean 값은 true, false이다.
3. 파이썬의 조건문 헤드는 'if 조건식:' 이며, 루비의 조건식 헤드는 'if 조건식' 이다.
Python :
input = 11
real = 11
if real == input:
print("Hello!")
else:
print("Who are you?")
Ruby :
input = 11
real = 11
if real == input
puts("Hello!")
else
puts("Who are you?")
end
Output :
Hello!
Python :
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 :
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
Output :
Who are you?
알게 된 내용 :
ELSE IF 구문이 파이썬에서는 elif, 루비에서는 elsif 이다.
출처 - opentutorials.org/
반응형
'[Python & Ruby]' 카테고리의 다른 글
[Python & Ruby] Comment (0) | 2020.12.12 |
---|---|
[Python & Ruby] IO (0) | 2020.12.11 |
[Python & Ruby] Variable (0) | 2020.12.11 |
[Python & Ruby] STRING (0) | 2020.12.10 |
[Python & Ruby] Hello World! (0) | 2020.12.10 |