ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [Ruby] Printing Data
    coding for food 2022. 7. 19. 09:36

    puts

    : 제일 기본적으로 쓰이는 것.

     

    print

    : 라인없이 기본적으로 만들어짐.

    print "hello"
    print "world"
    
    # the code above would print:
    # helloworld

    매뉴얼로 "\n", new line을 만들 수 있다. "\t"를 사용해서 whitespace(tab)띄워쓰기를 할 수 있음. 

    print "hello\n"
    print "\tworld\n"
    
    # the code above would print:
    # hello
    #   world

     

    p

    : 데이터 타입을 구분해서 보여진다. 

     

    p "hello"
    p 'goodbye'
    p "42"
    p 42
    
    # the code above would print:
    # "hello"
    # "goodbye"
    # "42"
    # 42

    p "42" 와 p 42는 문자와 숫자로 구분된다. 

    반면 puts "42"는 문자인지 숫자인지 알 수 없다.

Designed by Tistory.