string_strip.py 852 Bytes
Newer Older
xbe's avatar
xbe committed
1
2
3
4
5
6
print("".strip())
print(" \t\n\r\v\f".strip())
print(" T E S T".strip())
print("abcabc".strip("ce"))
print("aaa".strip("b"))
print("abc  efg ".strip("g a"))
7
8
9
10
11
12

print('   spacious   '.lstrip())
print('www.example.com'.lstrip('cmowz.'))

print('   spacious   '.rstrip())
print('mississippi'.rstrip('ipz'))
13
14
15
16
17
18
19
20
21
22

print(b'mississippi'.rstrip(b'ipz'))
try:
    print(b'mississippi'.rstrip('ipz'))
except TypeError:
    print("TypeError")
try:
    print('mississippi'.rstrip(b'ipz'))
except TypeError:
    print("TypeError")
23
24
25
26
27
28
29
30
31
32
33

# single-char subj string used to give a problem
print("a".strip())
print("a".lstrip())
print("a".rstrip())
print(" a".strip())
print(" a".lstrip())
print(" a".rstrip())
print("a ".strip())
print("a ".lstrip())
print("a ".rstrip())
34
35
36
37

# Test that stripping unstrippable string returns original object
s = "abc"
print(id(s.strip()) == id(s))