ruby vs python

언어/비교2016. 2. 10. 16:35
#Ruby
#2016 02 10
greeting = "Hello world"
for i in 0..greeting.length
puts(greeting[i])
end

puts ('Hello'[0]) #H
puts ('Hello'[1]) #e
puts ('Hello'[2]) #l
puts ('Hello'[3]) #l
puts ('Hello'[4]) #0

puts ('hello'.capitalize) #=> Hello
puts ('hello'.upcase) #=> HELLO
puts ('HELLO'.downcase) #=> hello
puts ('hello'.length) #=> 5

puts (greeting.sub('world', 'kim')) #=> Hello kim
puts (greeting) #=> Hello world
puts ("kim's \"tutorial\"")
# ---> puts("\") error
puts("\\") # \
puts("hello\nworld") #=> n -> new line
puts("hello\tworld") #=> hello world
puts("\a")

puts('hello \nworld') #=> hello \nworld



#python
#2016 02 10
greeting = "hello"
for i in range(0, len(greeting)):
print(greeting[i])

print("hello"[0]) # 'h'
print("hello"[1]) # 'e'
print("hello"[2]) # 'l'
print("hello"[3]) # 'l'
print("hello"[4]) # 'o'

print("hello".capitalize()) # 'Hello'
print("hello".upper()) # 'HELLO'
print("HELLO".lower()) # 'hello'
print(len("hello")) # 5
print("hello".__len__()) # 5
print("hello world".replace('world', 'programming')) #=> 'hello programming'
print("hello".count('l'))
print("kim's \"tutorial\"")

print("hello\nworld")
print("hello\tworld")
print("\a")
print('hello\nworld')


'언어 > 비교' 카테고리의 다른 글

dividen  (0) 2016.03.25
python go [python이 확실히 더 직관적이다.] 루비는 다시 볼 것  (0) 2016.02.26
python vs ruby  (0) 2016.02.13
python vs ruby  (0) 2016.02.13