logical operators in python 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: ** in python
#** is the exponent symbol in Python, so:
print(2 ** 3)
#output: 8
Example 4: or in python
# Syntax for Boolean expression with or in Python
exp1 or exp2
Example 5: logical operators in python
condition1 and condition2
condition1 or condition2
not condition