Operators
ASnake Documentation
Summary:
Operators in Python are symbols that perform actions on expressions. They can be:
- Unary which operates on one operand.
- Binary which operates on two operand.
- Ternary which operates on three operands. This page has a section which covers ternary.
It is a big topic that is covered better elsewhere. Skip to the ASnake specific section to see the operators it adds. Up until then, Python's operators will be listed with minimal explanation.
Unary Operators:
Operators that operate on one operand.
- Negation:
-x
- Bitwise NOT:
~x
- Logical NOT:
!x
Binary Operators:
Operators that operate on two operands.
Logical
Operators that perform logical operations.
- Logical And:
x && y
- Logical Or:
x || y
Linear Operators
Operators that perform arithmetic operations (usually on numerical values).
- Addition:
x + y
- Subtraction:
x - y
- Multiplication:
x * y
- Division:
x / y
- Modulo:
x % y
Bitwise
Operators that perform bitwise operations.
Examples:
- Bitwise And:
x | y
- Bitwise Or:
x & y
- Exclusive Or:
x ^ y
Conditions
Operators used for comparison. Very useful for conditionals.
- Equals:
a == b
- Not Equals:
a != b
- Less Than:
a < b
- Less Than Or Equal To:
a <= b
- Greater Than:
a > b
- Greater Than Or Equal To:
a >= b
ASnake's Operators:
Unary Increment/Decrement
- Incrementation:
x++
- Pre-Incrementation:
++x
- Decrementation:
x--
- Pre-Decrementation:
--x
Increments and decrements are covered on this page.
Binary Divmod
///
is a shortcut for the builtin Python function divmod
. It returns a tuple with the 0th element being the divide result, and the 1st element being the remainder result. You can use a index to access a specific value.
Example:
12 /// 2
# compiles to: divmod(12, 3)
# result: (6, 0)
12 /// 2 [0]
# result: 6
Tenary Operators:
There is only one, covered on the conditionals page.
Scroll to top