-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoolean.py
More file actions
executable file
·42 lines (30 loc) · 799 Bytes
/
Boolean.py
File metadata and controls
executable file
·42 lines (30 loc) · 799 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
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Mar 25 19:23:49 2021
@author: maherme
"""
#%%
# bool is a subclass of int:
print(issubclass(bool, int))
# booleans are singletone object, so they kept the same memory address
print(type(True), id(True), int(True))
print(type(False), id(False), int(False))
print(id(3 < 4)) # Notice is the same memory address than above
print((3 < 4) is True)
print(None is False)
#%%
# Be careful is you don't use parenthesis:
print((1 == 2) == False)
print(1 == 2 == False)
#%%
# Notice python is polymorphic, and booleans are a subclass of int:
print(1 + True)
print(100 * False)
print((True + True + True) % 2)
#%%
# Using the constructor of bool, only 0 will result in False
print(bool(0))
print(bool(1))
print(bool(100))
#%%