ruby学习笔记(10)-puts,p,print的区别
2010-02-22 14:02
330 查看
共同点:都是用来屏幕输出的。
不同点:
puts 输出内容后,会自动换行(如果内容参数为空,则仅输出一个换行符号);另外如果内容参数中有转义符,输出时将先处理转义再输出
p 基本与puts相同,但不会处理参数中的转义符号
print 基本与puts相同,但输出内容后,不会自动在结尾加上换行符
[code=ruby">s = "aaaa\nbb\tbb"
p s
p "****************"
puts s
p "****************"
print s
输出结果为(SciTE编辑器环境):
另外,在输出双字节的字符,比如全角英文或汉字时,p会输出对应的二个字节对应的数字,而非字符
s = "中"
p s
puts s
print s
[/code]
运行结果:
"\326\320"
中
中>Exit code: 0
不同点:
puts 输出内容后,会自动换行(如果内容参数为空,则仅输出一个换行符号);另外如果内容参数中有转义符,输出时将先处理转义再输出
p 基本与puts相同,但不会处理参数中的转义符号
print 基本与puts相同,但输出内容后,不会自动在结尾加上换行符
[code=ruby">s = "aaaa\nbb\tbb"
p s
p "****************"
puts s
p "****************"
print s
输出结果为(SciTE编辑器环境):
另外,在输出双字节的字符,比如全角英文或汉字时,p会输出对应的二个字节对应的数字,而非字符
s = "中"
p s
puts s
print s
[/code]
运行结果:
"\326\320"
中
中>Exit code: 0
相关文章推荐
- ruby学习笔记(10)-puts,p,print的区别
- 新人学ruby---print、puts和p的区别
- puts,p,print的区别
- puts,p,print的区别
- Ruby中puts、p和print的区别?
- puts,p,print的区别
- Ruby中print、p、puts的区别
- Ruby中print,puts,p的区别
- response.getWriter().write()与out.print()的区别
- echo print() print_r() var_dump()的区别
- response.getWriter().write()与out.print()的区别
- echo ,print,print_r的区别
- 关于response.getWriter().write()与out.print()的区别
- print_r与var_dump的区别
- PHP输出echo、print、print_r、printf、sprintf、var_dump的区别比较
- python的raw_input与print的区别实例
- PHP中echo,print,printf,sprintf的区别:
- 浅谈echo、print、var_dump()、print_r()的区别
- Java中printStackTrace()、toString()、getMessage()的区别
- php中echo print print_r的区别