summaryrefslogtreecommitdiffstatshomepage
path: root/tests/basics/unary_op.py
blob: 2239e2b2064766054c4c0bd218e2b1fb382aeabe (plain) (blame)
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
x = 1
print(+x)
print(-x)
print(~x)

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})

# check user instance
class A: pass
print(not A())

# check user instances derived from builtins
class B(int): pass
print(not B())
print(True if B() else False)
class C(list): pass
print(not C())
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)