码迷,mamicode.com
首页 > 其他好文 > 详细

LRTHW笔记七

时间:2014-09-01 22:22:03      阅读:146      评论:0      收藏:0      [点我收藏+]

标签: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. 
Its 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 

 

LRTHW笔记七

标签:style   blog   color   strong   ar   div   代码   log   sp   

原文地址:http://www.cnblogs.com/ufindme/p/3950009.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!