你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
Bicep 提供了用于将值转换为布尔值的 bool 函数。
Azure 资源管理器模板中的大多数逻辑函数在 Bicep 中将被替换为逻辑运算符。
bool
bool(arg1)
将参数转换为布尔值。
命名空间:sys。
参数
| 参数 | 必选 | 类型 | 说明 |
|---|---|---|---|
| arg1 | 是 | 字符串或整数 | 要转换为布尔值的值。 采用任何大小写字符组合的字符串值“true”(例如“True”、“TRUE”、“tRue”、“true”)被视为等效的,并表示布尔值 true,否则为 false。 整数值 0 被视为 false,所有其他整数被视为 true。 |
返回值
转换后的值的布尔值。
示例
以下示例演示如何对字符串或整数使用 bool。
output trueString1 bool = bool('true')
output trueString2 bool = bool('trUe')
output falseString1 bool = bool('false')
output falseString2 bool = bool('falSe')
output trueInt2 bool = bool(2)
output trueInt1 bool = bool(1)
output trueIntNeg1 bool = bool(-1)
output falseInt0 bool = bool(0)
上述示例中使用默认值的输出为:
| 名称 | 类型 | 值 |
|---|---|---|
| trueString1 | Bool | true |
| trueString2 | Bool | true |
| falseString1 | Bool | false |
| falseString2 | Bool | false |
| trueInt2 | Bool | true |
| trueInt1 | Bool | true |
| trueIntNeg1 | Bool | true |
| falseInt | Bool | false |
后续步骤
- 有关涉及逻辑值的其他操作,请参阅逻辑运算符。