例如我写的这行代码,print
and puts
产生不同的结果。
1.upto(1000).each { |i| print i if i % 2 == 0 }
puts
如果还没有一行,则在每个参数的末尾添加一个新行。
print
不添加新行。
例如:
puts [[1,2,3], [4,5,nil]]
将返回:
1
2
3
4
5
Whereas print [[1,2,3], [4,5,nil]]
会返回:
[[1,2,3], [4,5,nil]]
Notice how puts does not output the nil value whereas print does.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)