ds_seq.py 720 B

123456789101112131415161718192021222324
  1. shoplist = ['apple', 'mango', 'carrot', 'banana']
  2. name = 'swaroop'
  3. # Indexing or 'Subscription' operation #
  4. print('Item 0 is', shoplist[0])
  5. print('Item 1 is', shoplist[1])
  6. print('Item 2 is', shoplist[2])
  7. print('Item 3 is', shoplist[3])
  8. print('Item -1 is', shoplist[-1])
  9. print('Item -2 is', shoplist[-2])
  10. print('Character 0 is', name[0])
  11. # Slicing on a list #
  12. print('Item 1 to 3 is', shoplist[1:3])
  13. print('Item 2 to end is', shoplist[2:])
  14. print('Item 1 to -1 is', shoplist[1:-1])
  15. print('Item start to end is', shoplist[:])
  16. # Slicing on a string #
  17. print('characters 1 to 3 is', name[1:3])
  18. print('characters 2 to end is', name[2:])
  19. print('characters 1 to -1 is', name[1:-1])
  20. print('characters start to end is', name[:])