int1.py 891 Bytes
Newer Older
xyb's avatar
xyb committed
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
print(int(0))
print(int(1))
print(int(+1))
print(int(-1))

print(int('0'))
print(int('+0'))
print(int('-0'))
print(int('1'))
print(int('+1'))
print(int('-1'))
print(int('9'))
print(int('10'))
print(int('+10'))
print(int('-10'))
print(int('99'))
print(int('100'))
print(int('314'))
print(int(' 314'))
print(int('314 '))
print(int('  \t\t  314  \t\t  '))
print(int('  1  '))
print(int(' -3 '))

print(int('10', 16))
print(int('0o123', 0))
print(int('0x123', 16))
print(int('0X123', 16))
print(int('0O123', 8))
print(int('0B100', 2))


def test(value, base):
    try:
        print(int(value, base))
    except ValueError:
        print('ValueError')


test('  1x', 0)
xyb's avatar
xyb committed
41
test('  1' + chr(2) + '  ', 0)
xyb's avatar
xyb committed
42
43
44
45
46
47
48
49
50
51
52
53
54
test('', 0)
test(' ', 0)
test('  \t\t  ', 0)
test("\u0200", 0)
test('0x', 16)
test('0x', 0)
test('0o', 8)
test('0o', 0)
test('0b', 2)
test('0b', 0)
test('0b2', 2)
test('0o8', 8)
test('0xg', 16)