首页 > 代码库 > LRTHW笔记七
LRTHW笔记七
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 + end6puts 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
LRTHW笔记七
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。