# and
> 返回第一个假值参数；若所有参数都为真值，则返回最后一个参数。
- 官方英文原文：https://gohugo.io/functions/go-template/and/
- 本页规范地址：https://hugozh.cn/functions/go-template/and/
- 最近更新：2026-10-02
- 最后提交：912b1d3 chore(site): 添加 static/CNAME（hugozh.cn），供 GitHub Pages 等平台绑定自定义域名
- 签名：and VALUE...
- 返回类型：any
- 站点：Hugo 中文文档（https://hugozh.cn/）· 社区维护的非官方中文翻译，如有出入以官方英文原文为准

---
## 关于真值与假值

假值包括 `false`、`0`、任何 `nil` 指针或接口值、任何长度为零的数组、切片、映射或字符串，以及零值 `time.Time`。

其余一切值都是真值。

## 用法

`and` 函数从左到右依次求值，一旦结果可以确定就立即返回。

```go-html-template
{{ and 1 0 "" }} → 0 (int)
{{ and 1 false 0 }} → false (bool)

{{ and 1 2 3 }} → 3 (int)
{{ and "a" "b" "c" }} → c (string)
{{ and "a" 1 true }} → true (bool)

{{ and false (math.Div 1 0) }} → false (bool)
```

更多信息参见 Go 的 [`text/template`](https://pkg.go.dev/text/template) 文档。

