The difference between Ruby learning notes-puts,p,print
Common denominator: Both are used for screen output.
Different points:
Puts the output will be wrapped (if the content parameter is empty, only one newline symbol is output), and if there is an escape character in the content parameter, the output will first process the escape and then output
P is basically the same as puts, but does not handle escape symbols in Parameters
Print is basically the same as puts, but does not automatically add line breaks at the end after the content is output
1234567 |
s = "aaaa\nbb\tbb" p s p "****************" puts s p "****************" print s |
Output is (SciTE editor environment):
"AAAA\NBB\TBB"
"****************"
Aaaa
BB bb
"****************"
Aaaa
BB bb>exit code:0
In addition, when outputting double-byte characters, such as full-width English or Chinese characters, p will output the corresponding two bytes corresponding to the number, not the character
12345 |
s = "中" p s puts s print s |
Operation Result:
"\326\320"
In
Zhong >exit code:0
Ruby Learning Notes (1) the difference between-puts,p,print