DEV Community

Super Kai (Kazuya Ito)
Super Kai (Kazuya Ito)

Posted on

Create False in Python

Buy Me a Coffee

*Memo:

  • My post explains how to create True.

<bool()>:

print(bool(False))          # bool
print(bool(None))           # None
print(bool(0))              # int
print(bool(0.0))            # float
print(bool(0.0+0.0j))       # complex
print(bool([]))             # Empty list
print(bool(()))             # Empty tuple
print(bool(set()))          # Empty set
print(bool(frozenset([])))  # Empty frozenset
print(bool({}))             # Empty dict
print(bool(''))             # Empty str
print(bool(b''))            # Empty bytes
print(bool(bytearray(b''))) # Empty bytearray
print(bool(range(0)))       # Empty range
# False
Enter fullscreen mode Exit fullscreen mode

<not>:

print(not True)                       # bool
print(not 1)                          # int
print(not -1)                         # int
print(not 1.0)                        # float
print(not -1.0)                       # float
print(not float('nan'))               # float('nan')
print(not float('-nan'))              # float('-nan')
print(not float('inf'))               # float('inf')
print(not float('-inf'))              # float('-inf')
print(not 1.0+1.0j)                   # complex
print(not -1.0-1.0j)                  # complex
print(not complex('nan+nanj'))        # complex('nan+nanj')
print(not complex('-nan-nanj'))       # complex('-nan-nanj')
print(not complex('inf+infj'))        # complex('inf+infj')
print(not complex('-inf-infj'))       # complex('-inf-infj')
print(not [0])                        # list
print(not [[]])                       # list(Empty list)
print(not (0,))                       # tuple
print(not ((),))                      # tuple(Empty tuple)
print(not {0})                        # set
print(not {frozenset()})              # set(Empty frozenset)
print(not frozenset([0]))             # frozenset
print(not frozenset([frozenset([])])) # frozenset(Empty frozenset)
print(not {0:0})                      # dict
print(not {():()})                    # dict(Empty tuple:Empty tuple)
print(not iter([]))                   # Empty iterator
print(not iter([0]))                  # iterator
print(not iter([iter([])]))           # iterator(Empty iterator)
print(not ' ')                        # str
print(not b' ')                       # bytes
print(not bytearray(b' '))            # bytearray
print(not range(1))                   # range
# False
Enter fullscreen mode Exit fullscreen mode

<Others>:

print(10 < 5)          # <
print(5 > 10)          # >
print(10 <= 5)         # <=
print(5 >= 10)         # >=
print(10 == 5)         # ==
print(10 != 10)        # !=
print(10 in [5])       # in
print(True & False)    # &
print(False & True)    # &
print(False & False)   # &
print(True and False)  # and
print(False and True)  # and
print(False and False) # and
print(False | False)   # |
print(False or False)  # or
print(True ^ True)     # ^
print(False ^ False)   # ^
v1, v2 = [10, 5]
print(v1 is v2)        # is
v1, v2 = [10, 10]           
print(v1 is not v2)    # is not
# False
Enter fullscreen mode Exit fullscreen mode

Top comments (0)