2015-01-28 19:44:11 -05:00
|
|
|
x = 1
|
|
|
|
print(+x)
|
|
|
|
print(-x)
|
|
|
|
print(~x)
|
|
|
|
|
2014-01-27 18:15:32 -05:00
|
|
|
print(not None)
|
|
|
|
print(not False)
|
|
|
|
print(not True)
|
|
|
|
print(not 0)
|
|
|
|
print(not 1)
|
|
|
|
print(not -1)
|
|
|
|
print(not ())
|
|
|
|
print(not (1,))
|
|
|
|
print(not [])
|
|
|
|
print(not [1,])
|
|
|
|
print(not {})
|
|
|
|
print(not {1:1})
|
2015-12-08 07:34:25 -05:00
|
|
|
|
|
|
|
# check user instance
|
|
|
|
class A: pass
|
|
|
|
print(not A())
|
|
|
|
|
|
|
|
# check user instances derived from builtins
|
|
|
|
class B(int): pass
|
|
|
|
print(not B())
|
2020-02-20 06:30:49 -05:00
|
|
|
print(True if B() else False)
|
2015-12-08 07:34:25 -05:00
|
|
|
class C(list): pass
|
|
|
|
print(not C())
|
2020-02-20 06:30:49 -05:00
|
|
|
print(True if C() else False)
|
|
|
|
# type doesn't define unary_op
|
|
|
|
class D(type): pass
|
|
|
|
d = D("foo", (), {})
|
|
|
|
print(not d)
|
|
|
|
print(True if d else False)
|