-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconditional_logic.py
79 lines (51 loc) · 1.08 KB
/
conditional_logic.py
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
is_old = True
is_licensed = True
if is_old and is_licensed:
print('can drive')
if is_old:
print('older to drive')
elif is_licensed:
print('can drive')
else:
print('else block')
print('Outer if')
# Truthy and Falsy
# Truthy
print(bool('hello'))
# Falsy
print(bool(0))
username = 'test'
password = 'johnny'
if username and password:
print(f'{username}:{password}')
# Ternary Operator
is_test = True
can_message = 'message allowed' if is_test else 'not allowed'
print(can_message)
test_ternary = 'a' if True else 'b'
# Short Circuiting
is_test = False
is_test_two = True
print(is_test and is_test_two)
if is_test or is_test_two:
print('or operator')
# logical operators
print(4 == 5)
print('a' > 'A')
print(1 < 2 > 3 < 4)
print(1 != 2)
print(not (True))
is_magician = False
is_expert = True
# check if magician
if is_expert and is_magician:
print('magician')
elif is_magician and not is_expert:
print('not expert')
elif not is_magician:
print('not magician')
print(10==10.0)
a = [1,2,3]
b = [1,2,3]
print(a is b)
print(b is b) # match references