

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 在公式表達式中使用運算子
<a name="expression-operators"></a>

您可以在公式表達式中使用下列常見運算子。


| 運算子 | Description | 
| --- | --- | 
| `+` | 如果兩個運算元都是數字，則此運算子會新增左側和右側運算元。<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>您只能將此運算子與數值運算元搭配使用。 | 
| `%` | 傳回左運算元除以右運算元的餘數。結果與左側運算元具有相同的符號。此行為與模數操作不同。<br /><a name="operator-numbers-only"></a>您只能將此運算子與數值運算元搭配使用。 | 
| `x < y` | `1` 如果 小於 `x`，則傳回 `y`，否則傳回 `0`。 | 
| `x > y` | `1` 如果 `x` 大於 ，則傳回 `y`，否則傳回 `0`。 | 
| `x <= y` | `1` 如果 小於或等於 `x`，則傳回 `y`，否則傳回 `0`。 | 
| `x >= y` | `1` 如果 `x`大於或等於 ，則傳回 `y`，否則傳回 `0`。 | 
| `x == y` | `1` 如果 `x` 等於 ，則傳回 `y`，否則傳回 `0`。 | 
| `x != y` | `1` 如果 `x` 不等於 ，則傳回 `y`，否則傳回 `0`。 | 
| `!x` | `1` 如果評估`x`為 `0`(false)，則傳回 ，否則傳回 `0`。<br />`x` 評估為 false，如果：[See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/iot-sitewise/latest/userguide/expression-operators.html) | 
| `x and y` | `0` 如果評估`x`為 `0`(false)，則傳回 。否則， 會傳回 的評估結果`y`。<br />`x` 或 `y` 評估為 false，如果：[See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/iot-sitewise/latest/userguide/expression-operators.html) | 
| `x or y` | `1` 如果評估`x`為 `1`(true)，則傳回 。否則， 會傳回 的評估結果`y`。<br />`x` 或 `y` 評估為 false，如果：[See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/iot-sitewise/latest/userguide/expression-operators.html) | 
| `not x` | `1` 如果評估`x`為 `0`(false)，則傳回 ，否則傳回 `0`。<br />`x` 評估為 false，如果：[See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/iot-sitewise/latest/userguide/expression-operators.html) | 
| `[]`<br />`s[index]` | 傳回字串 索引`index`的字元`s`。這相當於 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_tw/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"` | 