Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 删除打印中的数组方括号和引号_Ruby - Fatal编程技术网

Ruby 删除打印中的数组方括号和引号

Ruby 删除打印中的数组方括号和引号,ruby,Ruby,我试图一次打印两个不同的数组对象(确切地说,每个数组都有一个随机项),结果显示得很奇怪: [“非”][“*”]% 嗯,并不奇怪。我知道这就是数组对象的外观,但我的问题是如何在没有括号和引号的情况下打印它们?这是我的密码: w = open('words.txt').read.split("\n").sample(1) print w s = Array["!", "@", "#", "$", "%", "^", "*", "+"].sample(1) print s 还有,这个%符号是怎么

我试图一次打印两个不同的数组对象(确切地说,每个数组都有一个随机项),结果显示得很奇怪:

[“非”][“*”]%

嗯,并不奇怪。我知道这就是数组对象的外观,但我的问题是如何在没有括号和引号的情况下打印它们?这是我的密码:

w = open('words.txt').read.split("\n").sample(1)

print w

s = Array["!", "@", "#", "$", "%", "^", "*", "+"].sample(1)
print s

还有,这个
%
符号是怎么回事?

回答了我自己的问题。使用
(1)
导致了该问题