51 lines
1.6 KiB
Python
Raw Normal View History

2023-07-18 22:31:39 +08:00
b = b'abc'
c = b"abc"
d = b'"abc"'
e = b"'abc'"
f = b'abc\'def'
g = b"abc\"def"
assert len(b) == 3
assert len(c) == 3
assert len(d) == 5
assert len(e) == 5
assert len(f) == 7
assert len(g) == 7
assert b[0] == 97 and b[1] == 98 and b[2] == 99
assert c[0] == 97 and c[1] == 98 and c[2] == 99
assert d[0] == 34 and d[1] == 97 and d[2] == 98 and d[3] == 99 and d[4] == 34
assert e[0] == 39 and e[1] == 97 and e[2] == 98 and e[3] == 99 and e[4] == 39
assert f[0] == 97 and f[1] == 98 and f[2] == 99 and f[3] == 39 and f[4] == 100 and f[5] == 101 and f[6] == 102
assert g[0] == 97 and g[1] == 98 and g[2] == 99 and g[3] == 34 and g[4] == 100 and g[5] == 101 and g[6] == 102
assert type(b[0:1]) == bytes
assert type(b[0]) == int
# Initialize the string variables
a = 'abc'
b = "abc"
c = '"abc"'
d = "'abc'"
e = 'abc\'def'
f = "abc\"def"
# Check the length of the strings
assert len(a) == 3
assert len(b) == 3
assert len(c) == 5
assert len(d) == 5
assert len(e) == 7
assert len(f) == 7
# Check the value of each character in the strings
assert a[0] == 'a' and a[1] == 'b' and a[2] == 'c'
assert b[0] == 'a' and b[1] == 'b' and b[2] == 'c'
assert c[0] == '"' and c[1] == 'a' and c[2] == 'b' and c[3] == 'c' and c[4] == '"'
assert d[0] == "'" and d[1] == 'a' and d[2] == 'b' and d[3] == 'c' and d[4] == "'"
assert e[0] == 'a' and e[1] == 'b' and e[2] == 'c' and e[3] == "'" and e[4] == 'd' and e[5] == 'e' and e[6] == 'f'
assert f[0] == 'a' and f[1] == 'b' and f[2] == 'c' and f[3] == '"' and f[4] == 'd' and f[5] == 'e' and f[6] == 'f'
# Check the type of the slices and characters
assert type(a[0:1]) == str
assert type(a[0]) == str
print('PASS')