Skip to content

Skip first n elements of a Python array

You can skip the first n elements of array. Though, note that you have to specify the index of the last element to exclude in a "arrays-start-at-1" manner. This also works for strings:

#Arrays
vegetables = ["apple", "banana", "lettuce", "carrot", "potato"]
no_fruits = vegetables[2:]

#Strings
text = "hello world"
no_hello = text[6:] # no_hello is 'world'

(source)

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.