谁能解释这个数组声明对我? [英] Can anyone explain this array declaration to me?
本文介绍了谁能解释这个数组声明对我?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
只是想知道最后一个逗号的presence之间的差异在阵列中,如果有任何可言
just wondering the difference between the presence of the last comma in the array, if there is any at all
>> [1,2,3]
=> [1, 2, 3]
>> [1,2,3,]
=> [1, 2, 3]
第二个数组仍然有效,也不例外引发
The second array still works, no exception raised
感谢
推荐答案
有什么区别。在Ruby中,你可以自由地尾随逗号添加到一个数组。它使语法如下:
There's no difference. In Ruby, you're free to add a trailing comma to an array. It makes syntax like this:
a = [
1,
2,
3,
]
有一个更好一点,在某些情况下(例如,如果要添加元素,只需添加一个 4
线,不必担心检查对于最后一行逗号分隔)。
A bit nicer, in some cases (e.g., if you want to add an element, you simply add a 4,
line and don't have to worry about checking for a comma on the last line).
这篇关于谁能解释这个数组声明对我?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文