Skip to content

Limit length of list

To limit the length of a list in Python we can shorten it with the :.

myList = ['hallo','hallo1','hallo2','hallo3','hallo4','hallo5','hallo6']
listLength = 3
shorterList = valueList[:listLength]
print(shorterList)

Comments