-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoperators.py
More file actions
54 lines (46 loc) · 917 Bytes
/
operators.py
File metadata and controls
54 lines (46 loc) · 917 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# Arithmetic operators
addition = 2 + 3
subtraction = 5 - 2
multiplication = 4 * 3
division = 10 / 2
modulus = 10 % 3
exponentiation = 2 ** 4
floor_division = 10 // 3
# Comparison operators
equal = 5 == 5
not_equal = 5 != 3
greater_than = 5 > 3
less_than = 2 < 4
greater_than_or_equal = 5 >= 5
less_than_or_equal = 3 <= 5
# Assignment operators
x = 5
x += 3
x -= 2
x *= 4
x /= 2
x %= 3
x **= 2
x //= 4
# Logical operators
and_operator = True and False
or_operator = True or False
not_operator = not True
# Bitwise operators
bitwise_and = 5 & 3
bitwise_or = 5 | 3
bitwise_xor = 5 ^ 3
bitwise_not = ~5
left_shift = 5 << 2
right_shift = 5 >> 2
# Membership operators
list_example = [1, 2, 3, 4, 5]
in_operator = 3 in list_example
not_in_operator = 6 not in list_example
# Identity operators
x = 5
y = 5
is_operator = x is y
is_not_operator = x is not y
# Ternary operator
result = "Even" if x % 2 == 0 else "Odd"