1.<< 和 >>代表左移或右移
puts 1<<2
输出结果为:4
代表1的二进制向左移动4位,即x<<y,x*2**y。平时用不到这种方法
2.字符串拼接
test = "you"
txt = "sb"
p test<<txt
输出结果为:yousb
3.数组添加元素
ar = Array.new
ar<<3
p ar
输出结果为:[3]
**字符串拼接和数组添加元素不能使用>>
1.<< 和 >>代表左移或右移
puts 1<<2
输出结果为:4
代表1的二进制向左移动4位,即x<<y,x*2**y。平时用不到这种方法
2.字符串拼接
test = "you"
txt = "sb"
p test<<txt
输出结果为:yousb
3.数组添加元素
ar = Array.new
ar<<3
p ar
输出结果为:[3]
**字符串拼接和数组添加元素不能使用>>
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。