小编oBa*_*oBa的帖子

替代python loop.last

我正在寻找使用Go模板循环数组,我想在循环中的最后一项添加一个额外的字符串.

在python中,我可以做到

{% for host in hosts %}
{{ host }}{% if loop.last %} ;{% endif %}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)

为了与Go实现相同的目标,下面是Go等效的片段.

{{ range $host := $hosts }}
{{$host}}
{{ end }}
Run Code Online (Sandbox Code Playgroud)

谢谢.

python go go-templates

8
推荐指数
1
解决办法
987
查看次数

标签 统计

go ×1

go-templates ×1

python ×1