t431.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. print "\nSTRINGS"
  2. s = 'hello'
  3. print ('h' in s) == True
  4. print ('H' in s) == False
  5. print ('e' not in s) == False
  6. print ('L' not in s) == True
  7. print ('hello' + ' world') == 'hello world'
  8. print 'a'*3 == 'aaa'
  9. print 2*'hello' == 'hellohello'
  10. s = '01234'
  11. print s[4] == '4'
  12. print s[-1] == '4'
  13. print s[0:3] == s[:3] == s[None:3] == '012'
  14. print s[0:] == s[0:None] == s[:] == '01234'
  15. print s[1:3] == '12'
  16. print s[-1:3] == ''
  17. print s[-3:3] == '2'
  18. print s[-4:-1] == '123'
  19. print s[0:5:1] == s[:5:1] == s[0::1] == s[0:5:] == s[0::] == s[:5:] == s[::1] == s[::] =='01234'
  20. print s[::-1] == '43210'
  21. print s[4:2:-1] == '43'
  22. print s[-1:2:-2] == '4'
  23. print len(s) == 5
  24. print min(s) == '0'
  25. print max(s) == '4'
  26. print "\nLISTS"
  27. l = [0,1,2,3,4]
  28. print (0 in l) == True
  29. print (5 in l) == False
  30. print (4 not in l) == False
  31. print ('hello' not in l) == True
  32. print ([0,1,2] + [3,4]) == l
  33. print [0]*3 == [0,0,0]
  34. print 2*[1,2] == [1,2,1,2]
  35. l2 = [[]]*3
  36. l2[0].append(3)
  37. print l2 == [[3],[3],[3]]
  38. print l[4] == 4
  39. print l[-1] == 4
  40. print l[0:3] == l[:3] == l[None:3] == [0,1,2]
  41. print l[0:] == l[0:None] == l[:] == [0,1,2,3,4]
  42. print l[1:3] == [1,2]
  43. print l[-1:3] == []
  44. print l[-3:3] == [2]
  45. print l[-4:-1] == [1,2,3]
  46. print l[0:5:1] == l[:5:1] == l[0::1] == l[0:5:] == l[0::] == l[:5:] == l[::1] == l[::] == [0,1,2,3,4]
  47. print l[::-1] == [4,3,2,1,0]
  48. print l[4:2:-1] == [4,3]
  49. print l[-1:2:-2] == [4]
  50. print len(l) == 5
  51. print min(l) == 0
  52. print max(l) == 4
  53. print "\nTUPLES"
  54. t = (0,1,2,3,4)
  55. print (0 in t) == True
  56. print (5 in t) == False
  57. print (4 not in t) == False
  58. print ('hello' not in t) == True
  59. print ((0,1,2) + (3,4)) == t
  60. print (0,)*3 == (0,0,0)
  61. print 2*(1,2) == (1,2,1,2)
  62. print t[4] == 4
  63. print t[-1] == 4
  64. print t[0:3] == t[:3] == t[None:3] == (0,1,2)
  65. print t[0:] == t[0:None] == t[:] == (0,1,2,3,4)
  66. print t[1:3] == (1,2)
  67. print t[-1:3] == ()
  68. print t[-3:3] == (2,)
  69. print t[-4:-1] == (1,2,3)
  70. print t[0:5:1] == t[:5:1] == t[0::1] == t[0:5:] == t[0::] == t[:5:] == t[::1] == t[::] == (0,1,2,3,4)
  71. print t[::-1] == (4,3,2,1,0)
  72. print t[4:2:-1] == (4,3)
  73. print t[-1:2:-2] == (4,)
  74. print len(t) == 5
  75. print min(t) == 0
  76. print max(t) == 4