> For the complete documentation index, see [llms.txt](https://roxy-wong.gitbook.io/pcep-30-02-practice-test-compendium/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://roxy-wong.gitbook.io/pcep-30-02-practice-test-compendium/part-2-or-study-pages-and-exam-section-questions/exam-block-1-computer-programming-and-python-fundamentals/module-1/1.2.1-pcep-30-02-practice-test-compendium-fundamental-concepts/1.2.1.4-pcep-30-02-practice-test-compendium-operators.md).

# 1.2.1.4 PCEP-30-02 Practice Test Compendium – Operators

## Operators

01\) An operator is a symbol that **determines an operation to perform**. The operator along with its arguments (operands) forms an expression that is subject to evaluation and provides a result.

02\) There are three basic groups of operators in Python:

* arithmetic, whose arguments are numbers;
* string, which operates on strings or strings and numbers;
* Boolean, which expects that their arguments are Boolean values.

03\) A unary operator is an operator with only one operand.

04\) A binary operator is an operator with two operands.

## Unary arithmetic operators

| Operator | Meaning                  | Example                  |
| :------: | ------------------------ | ------------------------ |
|    `-`   | Change argument's sign   | `-(-2)` is equal to `2`  |
|    `+`   | Preserve argument's sign | `+(-2)` is equal to `-2` |

## Binary arithmetic operators (ordered according to descending priority)

| Priority | Operator | Name               | Example  | Meaning | Result | Result Type                                                                                                                                                           |
| -------- | -------- | ------------------ | -------- | ------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Highest  | `**`     | Exponentiation     | `2 ** 3` | $$2^3$$ | `8`    | <ul><li><code>int</code> if both arguments are ints</li><li><code>float</code> otherwise</li></ul>                                                                    |
|          | `*`      | Multiplication     | `2 * 3`  | 2 × 3   | `6`    | <ul><li><code>int</code> if both arguments are ints</li><li><code>float</code> otherwise</li></ul>                                                                    |
|          | `/`      | Division           | `4 / 2`  | 4 ÷ 2   | `2.0`  | <ul><li>always <code>float</code></li><li>raises <code>ZeroDivisionError</code> when divider is zero</li></ul>                                                        |
|          | `//`     | Integer division   | `5 // 2` |         | `2`    | <ul><li><code>int</code> if both arguments are ints</li><li><code>float</code> otherwise</li><li>raises <code>ZeroDivisionError</code> when divider is zero</li></ul> |
|          | `%`      | Remainder (modulo) | `5 % 2`  | 5 mod 2 | `1`    | <ul><li><code>int</code> if both arguments are ints</li><li><code>float</code> otherwise</li><li>raises <code>ZeroDivisionError</code> when divider is zero</li></ul> |
| Lowest   | `+`      | Addition           | `2 + 1`  | 2 + 1   | `3`    | <ul><li><code>int</code> if both arguments are ints</li><li><code>float</code> otherwise</li></ul>                                                                    |
|          | `-`      | Subtraction        | `2 - 1`  | 2 − 1   | `1`    | <p></p><ul><li><code>int</code> if both arguments are ints</li><li><code>float</code> otherwise</li></ul>                                                             |

pairs of parentheses can be used to change the order of operations, for example:

* `2 + 3 * 4` evaluates to `24`
* `(2 + 3) * 4` evaluates to `20`

when operators of the same priority (other than `**`) are placed side-by-side in the same expression, they are evaluated **from left to right**: therefore, the expression:

```python
1 / 2 * 2
```

evaluates to `1.0`, not to `0.25`.

This convention is called **left-sided binding**.

when more than one `**` operator is placed side-by-side in the same expression, they are evaluated **from right to left**: therefore, the expression:

```python
2 ** 2 ** 3
```

evaluates to `256` ($$2^8$$), not to `64` ($$4^3$$) – this is **right-sided binding**.
