lua中的变量_有特殊含义吗? [英] variable _ in lua has a special meaning?

查看:45
本文介绍了lua中的变量_有特殊含义吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是lua/火炬的新手.我注意到变量_被大量使用,尤其是在迭代器中.示例:

I am a newbie to lua / torch. I notice that the variable _ is used a lot, especially in iterators. Example:

for _, node in ipairs(protos.rnn.forwardnodes) do
    a, b = whatever(a,b)
end

这个变量命名约定"(可以这么说)也用于其他情况,例如:

this 'variable naming convention' (so to speak) is used in other circumstances as well, as in:

local _,loss = optimizer(feval,params, optim_state)

_在许多可能的名称中,_是否有任何特殊含义?或者只是一个变量名称?

Does _ have any special meaning or is it just one more variable name, among the many possible names?

推荐答案

它通常用作一次性变量.它没有真实的"特殊含义,但是用来表示所指示的值并不重要.

It's usually used as a throwaway variable. It has no "real" special meaning, but is used to signify that the indicated value is not important.

当您要忽略变量时,仅包含下划线"_"的变量通常用作占位符...

The variable consisting of only an underscore "_" is commonly used as a placeholder when you want to ignore the variable...

此处(在命名部分下)了解更多信息.

Read more here (under the naming portion).

这篇关于lua中的变量_有特殊含义吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆