반응형
Python
∙ Interactive 기반
MacBook-Pro:~ Hevton$ python3
Python 3.9.0 (v3.9.0:9cf6752276, Oct 5 2020, 11:29:23)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> print("Hello World!");
Hello World!
>>> ^D
MacBook-Pro:~ Hevton$
실행할 때 : python3
나갈 때 : Ctrl + d
∙ File 기반
MacBook-Pro:p_r Hevton$ nano hello_python.py
->
print("Hello World!\n")
MacBook-Pro:p_r Hevton$ python3 hello_python.py
Hello World!
파일 만들 때 : Text Editor or nano or cat or vi etc...
실행할 때 : python3 파일
Ruby
∙ Interactive 기반
MacBook-Pro:~ Hevton$ irb
WARNING: This version of ruby is included in macOS for compatibility with legacy software.
In future versions of macOS the ruby runtime will not be available by
default, and may require you to install an additional package.
irb(main):001:0> print("Hello World!")
Hello World!=> nil
irb(main):002:0> ^D
MacBook-Pro:~ Hevton$
실행할 때 : irb
나갈 때 : Ctrl + d
∙ File 기반
MacBook-Pro:p_r Hevton$ nano hello_ruby.rb
->
print("Hello World!\n")
MacBook-Pro:p_r Hevton$ ruby hello_ruby.rb
Hello world!
파일 만들 때 : Text Editor or nano or cat or vi etc...
실행할 때 : ruby 파일
알게된 점 :
공통점 :
- python 과 ruby 모두 출력문은 print()를 이용한다.
- python 과 ruby 모두 세미콜론 대신에 개행으로 명령문을 구분할 수도 있다. (한줄로 입력할 때엔 세미콜론 사용)
차이점 :
- python에서는 print문이 자동 개행이 되고 ruby에서는 print문이 자동 개행이 되지 않는다.
따라서 ruby에서 자동개행을 하려면 puts()를 사용해야하고, 이 때문에 ruby에서는 print()보다는 puts()가 주로 많이 쓰인다.
반응형
'[Python & Ruby]' 카테고리의 다른 글
[Python & Ruby] IO (0) | 2020.12.11 |
---|---|
[Python & Ruby] 조건문 (Conditional Statement) (0) | 2020.12.11 |
[Python & Ruby] Variable (0) | 2020.12.11 |
[Python & Ruby] STRING (0) | 2020.12.10 |
[Python] Python3 설치 (0) | 2020.12.10 |