slice-bstr1.py 549 Bytes
Newer Older
1
print(b"123"[0:1])
2

3
print(b"123"[0:2])
4

5
print(b"123"[:1])
6

7
print(b"123"[1:])
8
9

# Idiom for copying sequence
10
print(b"123"[:])
11

12
print(b"123"[:-1])
13
14

# Weird cases
15
16
17
18
19
20
21
22
23
24
print(b"123"[0:0])
print(b"123"[1:0])
print(b"123"[1:1])
print(b"123"[-1:-1])
print(b"123"[-3:])
print(b"123"[-3:3])
print(b"123"[0:])
print(b"123"[:0])
print(b"123"[:-3])
print(b"123"[:-4])
25
26
27
28
29
# Range check testing, don't segfault, please ;-)
print(b"123"[:1000000])
print(b"123"[1000000:])
print(b"123"[:-1000000])
print(b"123"[-1000000:])
30
# No IndexError!
31
32
print(b""[1:1])
print(b""[-1:-1])