forked from syedmurad1/OOP-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path9oop-boolean.py
51 lines (37 loc) · 1.12 KB
/
9oop-boolean.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
a = 200
b = 33
if b > a:
print("b is greater than a")
else:
print("b is not greater than a")
print("--------------------------------------------------------")
# bool() function allows you to evaluate any value, and give you True or False in return
print(bool("Hello"))
print(bool(15))
c="hi"
d=12
print(bool(c))
print(bool(d))
print("--------------------------------------------------------")
# there are not many values that evaluate to False, except empty values, such as (), [], {}, "", the number 0, and the value None. And of course the value False evaluates to False
bool(False)
bool(None)
bool(0)
bool("")
bool(())
bool([])
bool({})
print("--------------------------------------------------------")
# One more value, or object in this case, evaluates to False, and that is if you have an object that is made from a class with a __len__ function that returns 0 or False
class myclass():
def __len__(self):
return 0
myobj = myclass()
print(bool(myobj))
print("--------------------------------------------------------")
def myFunction():
return True # try false
if myFunction():
print("YES!")
else:
print("NO!")