-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoperators.py
More file actions
110 lines (81 loc) · 3.05 KB
/
Copy pathoperators.py
File metadata and controls
110 lines (81 loc) · 3.05 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# ── OPERATORS IN PYTHON ───────────────────
# Operators are symbols that perform
# operations on variables and values
# ── 1. ARITHMETIC OPERATORS ───────────────
a = 10
b = 3
print(a + b) # 13 → addition
print(a - b) # 7 → subtraction
print(a * b) # 30 → multiplication
print(a / b) # 3.3333 → division (always float)
print(a // b) # 3 → floor division (removes decimal)
print(a % b) # 1 → modulus (remainder)
print(a ** b) # 1000 → power (10³)
#after run you can see this on output panel or type python + file name in your terminal and you will see the number output.
# ── 2. COMPARISON OPERATORS ───────────────
# These compare two values
# Result is always True or False (Boolean!)
a = 10
b = 3
print(a == b) # False → equal to
print(a != b) # True → not equal to
print(a > b) # True → greater than
print(a < b) # False → less than
print(a >= b) # True → greater or equal
print(a <= b) # False → less or equal
# Every comparison returns True or False!
is_greater = a > b
print(is_greater) # True
is_equal = a == b
print(is_equal) # False
# ── 3. LOGICAL OPERATORS ──────────────────
# AND, OR, NOT — same as Discrete Math!
print(True and True) # True
print(True and False) # False
print(True or False) # True
print(not True) # False
# Real example:
age = 18
has_id = True
print(age >= 18 and has_id) # True → can enter!
print(age >= 18 or has_id) # True
print(not has_id) # False
# ── 3. LOGICAL OPERATORS ──────────────────
# AND → both must be True
# OR → at least one must be True
# NOT → flips True to False or vice versa
print(True and True) # True
print(True and False) # False
print(False and False) # False
print(True or False) # True
print(False or False) # False
print(not True) # False
print(not False) # True
# ── REAL LIFE EXAMPLE ─────────────────────
age = 20
has_id = True
is_student = False
# AND → both conditions must be true
print(age >= 18 and has_id) # True
print(age >= 18 and is_student) # False
# OR → at least one true
print(age >= 18 or is_student) # True
# NOT → reverse it
print(not is_student) # True
# ── 4. ASSIGNMENT OPERATORS ───────────────
# shortcuts for updating variable values
score = 100
print(score) # 100
score += 10 # same as score = score + 10
print(score) # 110
score -= 20 # same as score = score - 20
print(score) # 90
score *= 2 # same as score = score * 2
print(score) # 180
#this *= 2 is used for squared 9's square is 18, how it work..
score //= 3 # same as score = score // 3
print(score) # 60
score **= 2 # same as score = score ** 2
print(score) # 3600
score %= 100 # same as score = score % 100
print(score) # 0