List Slicing

Run Settings
LanguagePython
Language Version
Run Command
# list slicing amazon_cart = [ 'notebooks', 'consoles', 'sunglasses', 'toys', 'grapes' ] print(amazon_cart[::2]) # In string we have noticed we cannot change the objs via indexing. # But here we can do it here! # Strings are immutable while lists are mutable. amazon_cart[0] = 'Laptop' print(amazon_cart) #Notebook is replaced by laptop! # Everytime we do a list slicing we create a new copy of the list in the memory to prove this sale = amazon_cart[0:3] print() # we now have 2 copies of the same list. print(sale) print(amazon_cart)
Editor Settings
Theme
Key bindings
Full width
Lines