2. 동적 객체지향 스트립트 프로그래밍 언어
파이썬과루비
Python & Ruby
Python Ruby
3. Python
• 1991년에 귀도 반 로섬
이 고안
• 구글, 인스타그램에서 사
용하고 있는 언어
• 사용사례
https://www.python.o
rg/about/success/#da
tabases
Ruby
• 1995년에 일본사람이
고안함
• 애플, 트위터, 깃허브에
서 사용하고 있는 언어
• 사용사례
https://www.ruby-
lang.org/ko/document
ation/success-stories/
파이썬과루비
Python & Ruby
4. 장단점
Python
• 장점
1. 문법이 간결하고 쉽다.
2. 생산성이 높다. 즉, 개발기간을 단축할 수 있다.
3. 개발하지 못하는 분야가 거의 없다고 한다. (웹서버 개발, 기
계학습 알고리즘 개발 등 광범위)
• 단점
1. 멀티 스레딩에 문제가 있다.
2. 인터프리터 언어이지만 속도가 컴파일하는 언어들 보다 느리
다.
3. 버전2와 3의 호환이 잘 안되서 불편함.
4. 들여쓰기가 문법이어서 자율성이 너무 없다고 하는 사람도
있음.
Ruby
• 장점
1. 파이썬보다 더 간결함과 생산성이 강조된 언어.
2. 확장성과 이식성이 높다. 다른 언어로 개발된 라이
브러리를 루비 위에 구현할 수 있다.
• 단점
1. 파이썬보다도 속도가 느리다.
2. 다른 언어에 비해 사용자가 적다.
11. x = 10
y = 5
name = ‘imdasom’
print( x + y )
print( “My name is ” + name )
x = 10
y = 5
name = ‘imdasom’
puts( x + y )
puts( “My name is ” + name )
변수
Variable
Python Ruby
15
My name is imdasom
15
My name is imdasom
14. name = input(“Enter name : ”)
pwd = input("Enter password : ")
if name == "imdasom" and pwd == "11“ :
print("Hello, imdasom!")
elif name != "imdasom" or pwd != "11“ :
print(“Try again!")
else :
print("Who are you?")
# if – elif - else
print("Enter name : ")
name = gets.chomp()
print("Enter password : ")
pwd = gets.chomp()
if name == "imdasom" and pwd == "11"
puts("Hello, imdasom!")
elsif name != "imdasom" or pwd != "11"
puts(“Try again!")
else
puts("Who are you?")
end
# if – elsif – else – end
조건문
Condition
Python Ruby
16. 1. i = 0
2. while i < 10:
3. if i == 4:
4. break
5. print("print('Hello world " + str(i*9)
+ "')")
6. i = i+1
1. i=0
2. while i < 10 do
3. if i == 4
4. break
5. puts("puts('Hello world "+
(i*9).to_s() +"')")
6. i = i+1
7. end
Python Ruby
print('Hello world 0')
print('Hello world 9')
print('Hello world 18')
print('Hello world 27')
print('Hello world 0')
print('Hello world 9')
print('Hello world 18')
print('Hello world 27')
반복문while
Loop
< 루비 >
‘Hello world #{i*9}’
문자열 안에서 변수 사용 가능
17. 1. for item in range(5, 11):
2. print(item)
1. for item in (5...11) do
2. puts(item)
3. end
Python Ruby
5
6
7
8
9
10
5
6
7
8
9
10
반복문for
Loop
18. 1. name = input("Enter your name : ")
2. members = ['dasom', 'minjung', 'sungha']
3. for member in members:
4. if member == name:
5. print('Hello,
'+member)
6. import sys
7. sys.exit()
8. print('Who are you?')
1. print("Enter your name : ")
2. name = gets.chomp()
3. members = ['dasom', 'minjung', 'sungha']
4. for member in members do
5. if member == name
6. puts("Hello,
"+member)
7. exit
8. end
9. end
10. puts('Who are you?')
Python Ruby
반복문for
Loop