-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path018-bool.py
More file actions
30 lines (26 loc) · 888 Bytes
/
018-bool.py
File metadata and controls
30 lines (26 loc) · 888 Bytes
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
"""
Return the boolean value of an object
-------------------------------------
Input (object) any object
Return (boolean) Always True, except:
- object is None
- object is empty
- object is False
- object is 0
"""
# List contains elements
cars = ["Audi", "BMW", "Chrysler", "Dodge"]
boolean_cars = bool(cars)
print('Object: {}\nBoolean: {}'.format(cars, boolean_cars))
# Empty list
empty_list = []
boolean_empty_list = bool(empty_list)
print('\nObject: {}\nBoolean: {}'.format(empty_list, boolean_empty_list))
# Integer
number = 25
boolean_number = bool(number)
print('\nObject: {}\nBoolean: {}'.format(number, boolean_number))
# Zero
zero_number = 0
boolean_zero_number = bool(zero_number)
print('\nObject: {}\nBoolean: {}'.format(zero_number, boolean_zero_number))