-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path18_Python_Booleans.py
95 lines (76 loc) · 1.44 KB
/
18_Python_Booleans.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# Python Booleans
print("Python Booleans")
# example 1
print("Example 1")
print(10 > 8) # true
print(5 < 9) # true
print(2 == 3) # false
print("")
# example 2
print("Example 2")
num1 = 99
num2 = 33
if num1 > num2:
print("Number 1 is bigger.")
else:
print("Number 1 is smaller.")
print("")
# evaluate values
print("Evaluate values:")
print(bool("This is a string")) # true
print(bool(10)) # true
print("")
# evaluate variables
print("Evaluate variables:")
a1 = 5
a2 = 1
print(bool(a1)) # true
print(bool(a2)) # true
print("")
# most values are true except some
print("Most values are true except some:")
txt1 = "Hi"
print(bool(txt1)) # true
txt2 = ""
print(bool(txt2)) # false
x1 = 25
print(bool(x1)) # true
x2 = 0
print(bool(x2)) # false
l1 = ['apple', 'mango', 'watermelon']
print(bool(l1)) # true
l2 = []
print(bool(l2)) # false
print("")
# the false values
print("The false values:")
print(bool(False))
print(bool(None))
print(bool(0))
print(bool(""))
print(bool(()))
print(bool({}))
print(bool([]))
print("")
# functions can return a boolean
print("Functions can return a boolean:")
# example 1
print("Example 1:")
def function1():
return True
result = function1()
print(result) # true
# example 2
print("Example 2:")
def function2():
return False
if function2():
print("Yes!")
else:
print("No.") # No
print("")
# using a built-in function
print("Using a built-in function:")
z = 1000
print(isinstance(z, int)) # true
print("")