Ruby 矩阵append()函数

Ruby 矩阵append()函数

Array#append()是一个数组类方法,用于在数组的末尾添加元素。

语法。Array.append()

参数: – 用于添加元素的数组。
– 要添加的元素

返回。在最后添加元素后的数组。

例子 #1 :

# Ruby code for append() method
# adding elements at the end
    
# declaring array
a = [18, 22, 33, 4, 5, 6]
    
# declaring array
b = [5, 4, 22, 1, 88, 9]
    
# declaring array
c = [18, 22, 33, 40, 50, 6]
   
# appending array or element at the end of the array
puts "adding elements in a : #{a.append(b)}\n\n"
   
puts "adding elements in b : #{b.append("ratttt")}\n\n"
   
puts "adding elements in c : #{c.append(b)}\n\n"

输出:

adding elements in a : [18, 22, 33, 4, 5, 6, [5, 4, 22, 1, 88, 9]]

adding elements in b : [5, 4, 22, 1, 88, 9, "ratttt"]

adding elements in c : [18, 22, 33, 40, 50, 6, [5, 4, 22, 1, 88, 9, "ratttt"]]

例子 #2 :

# Ruby code for append() method
# adding elements at the end
    
# declaring array
a = ["abc", "xyz", "dog"]
    
# declaring array
b = ["cow", "cat", "dog"]
    
# declaring array
c = ["cat", "1", "dog"]
   
# appending array or element at the end of the array
puts "adding elements in a : #{a.append(b)}\n\n"
   
puts "adding elements in b : #{b.append("ratttt")}\n\n"
   
puts "adding elements in c : #{c.append(b)}\n\n"

输出:

adding elements in a : ["abc", "xyz", "dog", ["cow", "cat", "dog"]]

adding elements in b : ["cow", "cat", "dog", "ratttt"]

adding elements in c : ["cat", "1", "dog", ["cow", "cat", "dog", "ratttt"]]

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程