Advertisement
Nenogzar

Untitled

Jan 17th, 2024
1,088
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.85 KB | None | 0 0
  1. me_list =   [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
  2. # indexes:   0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
  3. # reversed:-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1
  4.  
  5. print(f"{me_list[1] = }")           # = 2
  6. print(f"{me_list[-1] = }")          # = 11
  7. print(f"{me_list[0:6] = }")         # = [1, 2, 3, 4, 5, 6]
  8. print(f"{me_list[-11:-5] = }")      # = [1, 2, 3, 4, 5, 6]
  9.  
  10. print(f"{me_list[3:7] = }")         # = [4, 5, 6, 7]
  11. print(f"{me_list[-8:-4] = }")       # = [4, 5, 6, 7]
  12.  
  13. print(f"{me_list[1:11:2] = }")      # = [2, 4, 6, 8, 10]
  14. print(f"{me_list[-10:-1:2] = }")    # = [2, 4, 6, 8, 10]
  15.  
  16. print(f"{me_list[-2:-11:-2] = }")   # = [10, 8, 6, 4, 2]
  17. print(f"{me_list[9:1:-2] = }")      # = [10, 8, 6, 4, 2]
  18.  
  19. print(f"{me_list[11:6:-1] = }")     #  = [11, 10, 9, 8]
  20. print(f"{me_list[-1:-5:-1] = }")    # = [11, 10, 9, 8]
  21. print(f"{me_list[-1:6:-1] = }")     # = [11, 10, 9, 8]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement