User Tools

Site Tools


scripting:python

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
scripting:python [2024/09/24 05:49] jotasandokuscripting:python [2024/12/23 13:46] (current) – S jotasandoku
Line 330: Line 330:
   """)   """)
 \\ \\
-Slicing lists\\ +== SLICING === 
-  print namelist[:2]   prints up to but not including index 2. So and 1.+ 
 +  # [:2] - First 2 elements 
 +  print("[:2] ->",  x[:2])  [0, 1] 
 + 
 +  # [2:] - Everything from index 2 onwards 
 +  print("[2:] ->", x[2:])  # [2, 3, 4, 5, 6, 7, 8, 9] 
 + 
 +  # [-2:] - Last 2 elements 
 +  print("[-2:] ->", x[-2:])  # [8, 9] 
 + 
 +  # [:-2] - Everything EXCEPT last 2 elements 
 +  print("[:-2] ->", x[:-2])  # [01, 2, 3, 4, 5, 6, 7] 
 + 
 + 
 + 
 \\ \\
 Updating list Updating list
scripting/python.1727156944.txt.gz · Last modified: by jotasandoku