t502.py 756 B

1234567891011121314151617181920212223242526272829303132333435
  1. class A:
  2. def __getitem__(self, slices):
  3. return slices
  4. a = A()
  5. print a[1]
  6. print a[0:2]
  7. print a[:2]
  8. print slice(2)
  9. print a[1:]
  10. print a[:]
  11. print a[::]
  12. print a[::-1]
  13. print a[0,1:2]
  14. print a[0:2,2:30:1]
  15. assert(a[1]==1)
  16. assert(a[0:2]==slice(0,2))
  17. assert(a[0,1:2]==(0,slice(1,2)))
  18. assert(a[0:2,2:30:1]==(slice(0,2), slice(2,30,1)))
  19. assert(slice(0,2) == slice(0,2))
  20. assert(slice(0,2) < slice(1,2))
  21. assert(slice(0,2) < slice(1,1))
  22. assert(slice(2) < slice(0,2))
  23. assert(slice(1,2) < slice(1,2,3))
  24. assert(slice(1,2,3) < slice(1,2,4))
  25. assert(slice(1,-1) < slice(1,1))
  26. assert(slice(0,1) < slice(1,-1))
  27. assert(a["foo"] == "foo")
  28. assert(a["foo":(1,2):True].start == "foo")
  29. assert(a["foo":(1,2):True].stop == (1,2))
  30. assert(a["foo":(1,2):True].step == True)