// python operator code example
Example 1: operators in python
# Python Operators
Operator Name Example
+ Addition x + y
- Subtraction x - y
* Multiplication x * y
/ Division x / y
** Exponentiation x ** y
// Floor division x // y
Example 2: |= operator python
>>> s1 = {"a", "b", "c"}
>>> s2 = {"d", "e", "f"}
>>> # OR, |
>>> s1 | s2
{'a', 'b', 'c', 'd', 'e', 'f'}
>>> s1 # `s1` is unchanged
{'a', 'b', 'c'}
>>> # In-place OR, |=
>>> s1 |= s2
>>> s1 # `s1` is reassigned
{'a', 'b', 'c', 'd', 'e', 'f'}
Example 3: or in python
# Syntax for Boolean expression with or in Python
exp1 or exp2
Example 4: logical operators in python
condition1 and condition2
condition1 or condition2
not condition
Example 5: logical operator in python
# logical and operator
# return first operands if false otherwise second operands
0 and 3
# output = 0
3 and 0
# output = 0
3 and 5
# output = 5