Home › Python Tutorial › Python lists
Python lists
Ordered, changeable collections.
Lists use square brackets. append adds an item, sort orders them, and a negative index counts from the end. A list comprehension builds a list in one line.
Example code
fruits = ["pear", "apple"]
fruits.append("plum")
fruits.sort()
print(fruits)
print(fruits[-1], len(fruits))
print([x * 2 for x in range(4)])