Truthy values
Def: any expression or an entity that gets evaluated to a Boolean true
ex: True, not False, any comparison operation that gets evaluated to a True and any variable that is referring to anything but a None or a Null value
Falsy Values
Def: any expression or an entity that gets evaluated to a false
ex: False, not True, any comparison that gets evaluated to a False and any variable that is precisely referring to None or Null value
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
|
print('Examples of Truthy Values')
# Example 1
if True:
print('1. Yay!')
# Example 2
if not False:
print('2. Yay!')
# Example 3
if not 0:
print('3. Yay!')
# Example 4
if 1:
print('4. Yay!')
# Example 5
if 'Gautham':
print('5. Yay!')
# Example 6
if not '':
print('6. Yay!')
# Example 7
if 1 > 0:
print('7. Yay!')
# Example 8
if 0 < 1:
print('8. Yay!')
# Example 9
if not 1 < 0:
print('9. Yay!')
print('Examples of Falsy Values')
# Example 1
if False:
print('10. Yay!')
# Example 2
if not True:
print('11. Yay!')
# Example 3
if not 1:
print('12. Yay!')
# Example 4
if 0:
print('13. Yay!')
# Example 5
if not 'Gautham':
print('14. Yay!')
# Example 6
if '':
print('15. Yay!')
# Example 7
if not 1 > 0:
print('16. Yay!')
# Example 8
if not 0 < 1:
print('17. Yay!')
# Example 9
if 1 < 0:
print('18. Yay!')
|
Video on Youtube:
Youtube channel: Gautham S Kolluru
My Github Link: https://github.com/gauthamkolluru