标签:style blog color strong ar div 代码 log sp
puts "Mary had a little lamb. " puts "It‘s fleese was white as #{‘snow‘}." puts "And everywhere that Mary went." puts "." * 10 # what‘d that do? end1 = "C" end2 = "h" end3 = "e" end4 = "e" end5 = "s" end6 = "e" end7 = "B" end8 = "u" end9 = "r" end10 = "g" end11 = "e" end12 = "r" # watch that print VS. puts on this line what‘s it do? print end1 + end2 + end3 + end4 + end5 + end6 puts end7 + end8 + end9 + end10 + end11 + end12
结果:
Mary had a little lamb. It‘s fleese was white as snow. And everywhere that Mary went. .......... CheeseBurger
注意:
print和puts中一样,对于字符串变量,他们都是通过“+”将变量连接从而形成一个长的字符串;
print 一般输出结果后面不换行,而puts输出字串后会换行;
注意省略号的生成,由此可猜想,如果这样的结果是什么:
代码:
puts "01101 " * 8
输出:
[ufindme@ufindme rubywork]$ ruby ex7-2.rb
01101 01101 01101 01101 01101 01101 01101 01101
标签:style blog color strong ar div 代码 log sp
原文地址:http://www.cnblogs.com/ufindme/p/3950009.html