forked from WebJournal/journaldev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_all_examples.py
More file actions
62 lines (41 loc) · 1.15 KB
/
python_all_examples.py
File metadata and controls
62 lines (41 loc) · 1.15 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
# iterable has all True
list_bools = [True, True, True]
print(all(list_bools))
# iterable all elements are not True
list_bools = [True, True, False]
print(all(list_bools))
# iterable is empty
list_bools = []
print(all(list_bools))
# iterable elements are True string
list_strs = ['True', 'True']
print(all(list_strs))
# iterable all elements are true string with different case
list_strs = ['True', 'true']
print(all(list_strs))
# iterable all elements are not true string
list_strs = ['abc', 'true']
print(all(list_strs))
# iterable all elements are empty string
list_strs = ['', 'true']
print(all(list_strs))
# iterable objects example
class Person:
name = ""
def __init__(self, n):
self.name = n
#comment and check output
def __bool__(self):
print('bool function called')
if len(self.name) > 3:
return True
else:
return False
# comment and check output
def __len__(self):
print('len function called')
return len(self.name)
list_objs = [Person("Pankaj"), Person("Lisa")]
print(all(list_objs))
list_objs = [Person("A"), Person("David")]
print(all(list_objs))