

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 在公式表达式中使用运算符
<a name="expression-operators"></a>

您可以在公式表达式中使用以下常见的运算符。


| 运算符 | 说明 | 
| --- | --- | 
| `+` | 如果两个操作数都是数字，则此运算符将左右操作数相加。<br />如果任一操作数是字符串，则此运算符将左右操作数连接为字符串。例如，表达式的 `1 + 2 + " is three"` 计算结果为 `"3 is three"`。连接字符串最多可以包含 1024个字符。如果字符串超过 1024 个字符，则 AWS IoT SiteWise 不会为该计算输出数据点。 | 
| `-` | 从左侧操作数中减去右侧操作数。<br /><a name="operator-numbers-only"></a>只能将此运算符与数字操作数一起使用。 | 
| `/` | 左侧操作数除以右侧操作数。<br /><a name="operator-numbers-only"></a>只能将此运算符与数字操作数一起使用。 | 
| `*` | 将左右操作数相乘。<br /><a name="operator-numbers-only"></a>只能将此运算符与数字操作数一起使用。 | 
| `^` | 将左操作数作为右操作数的幂（指数）。<br /><a name="operator-numbers-only"></a>只能将此运算符与数字操作数一起使用。 | 
| `%` | 返回左侧操作数除以右侧操作数得到的余数。结果具有与左侧操作数相同的符号。此行为不同于 modulo 操作。<br /><a name="operator-numbers-only"></a>只能将此运算符与数字操作数一起使用。 | 
| `x < y` | 如果 `x` 小于 `y`，则返回 `1`，否则，返回 `0`。 | 
| `x > y` | 如果 `x` 大于 `y`，则返回 `1`，否则，返回 `0`。 | 
| `x <= y` | 如果 `x` 小于或等于 `y`，则返回 `1`，否则，返回 `0`。 | 
| `x >= y` | 如果 `x` 大于或等于 `y`，则返回 `1`，否则，返回 `0`。 | 
| `x == y` | 如果 `x` 等于 `y`，则返回 `1`，否则，返回 `0`。 | 
| `x != y` | 如果 `x` 不等于 `y`，则返回 `1`，否则，返回 `0`。 | 
| `!x` | 如果 `x` 等于 `0`（假），则返回 `1`，否则，返回 `0`。<br />如果出现以下情况，则 `x` 的计算结果为假：[See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/iot-sitewise/latest/userguide/expression-operators.html) | 
| `x and y` | 如果 `x` 的计算结果为 `0`（假），则返回 `0`。否则，返回 `y` 的计算结果。<br />如果出现以下情况，则 `x` 或 `y` 的计算结果为假：[See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/iot-sitewise/latest/userguide/expression-operators.html) | 
| `x or y` | 如果 `x` 等于 `1`（真），则返回 `1`。否则，返回 `y` 的计算结果。<br />如果出现以下情况，则 `x` 或 `y` 的计算结果为假：[See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/iot-sitewise/latest/userguide/expression-operators.html) | 
| `not x` | 如果 `x` 等于 `0`（假），则返回 `1`，否则，返回 `0`。<br />如果出现以下情况，则 `x` 的计算结果为假：[See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/iot-sitewise/latest/userguide/expression-operators.html) | 
| `[]`<br />`s[index]` | 返回字符串 `s` 索引 `index` 上的字符。这等同于 Python 中的索引语法。

**Example 示例**  
+ `"Hello!"[1]` 返回 `e`。
+ `"Hello!"[-2]` 返回 `o`。 | 
| `[]`<br />`s[start:end:step]` | 返回字符串 `s` 的片段。这等同于 Python 中的切片语法。此运算符具有以下参数：[See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/iot-sitewise/latest/userguide/expression-operators.html)<br />您可以省略 `step` 参数以使用其默认值。例如，`s[1:4:1]` 等同于 `s[1:4]`。<br />参数必须是整数或 [无](expression-constants.md#none-definition) 常量。如果指定`none`，则 AWS IoT SiteWise 使用该参数的默认值。

**Example 示例**  
+ `"Hello!"[1:4]` 返回 `"ell"`。
+ `"Hello!"[:2]` 返回 `"He"`。
+ `"Hello!"[3:]` 返回 `"lo!"`。
+ `"Hello!"[:-4]` 返回 `"He"`。
+ `"Hello!"[::2]` 返回 `"Hlo"`。
+ `"Hello!"[::-1]` 返回 `"!olleH"`。 | 