literal.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. b = b'abc'
  2. c = b"abc"
  3. d = b'"abc"'
  4. e = b"'abc'"
  5. f = b'abc\'def'
  6. g = b"abc\"def"
  7. assert len(b) == 3
  8. assert len(c) == 3
  9. assert len(d) == 5
  10. assert len(e) == 5
  11. assert len(f) == 7
  12. assert len(g) == 7
  13. assert b[0] == 97 and b[1] == 98 and b[2] == 99
  14. assert c[0] == 97 and c[1] == 98 and c[2] == 99
  15. assert d[0] == 34 and d[1] == 97 and d[2] == 98 and d[3] == 99 and d[4] == 34
  16. assert e[0] == 39 and e[1] == 97 and e[2] == 98 and e[3] == 99 and e[4] == 39
  17. 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
  18. 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
  19. assert type(b[0:1]) == bytes
  20. assert type(b[0]) == int
  21. # Initialize the string variables
  22. a = 'abc'
  23. b = "abc"
  24. c = '"abc"'
  25. d = "'abc'"
  26. e = 'abc\'def'
  27. f = "abc\"def"
  28. # Check the length of the strings
  29. assert len(a) == 3
  30. assert len(b) == 3
  31. assert len(c) == 5
  32. assert len(d) == 5
  33. assert len(e) == 7
  34. assert len(f) == 7
  35. # Check the value of each character in the strings
  36. assert a[0] == 'a' and a[1] == 'b' and a[2] == 'c'
  37. assert b[0] == 'a' and b[1] == 'b' and b[2] == 'c'
  38. assert c[0] == '"' and c[1] == 'a' and c[2] == 'b' and c[3] == 'c' and c[4] == '"'
  39. assert d[0] == "'" and d[1] == 'a' and d[2] == 'b' and d[3] == 'c' and d[4] == "'"
  40. 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'
  41. 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'
  42. # Check the type of the slices and characters
  43. assert type(a[0:1]) == str
  44. assert type(a[0]) == str
  45. print('PASS')