3.2 Lists
Lists are a powerful and versatile type of object in Python.
3.2.1 Creating lists
The primary method to create a list of items is to put square brackets around them. Separate the items with commas.
brands = ["Fender", "Gibson", "Ibanez"]
brands
['Fender', 'Gibson', 'Ibanez']
A list can be empty, which means it contains no items. The list function with no arguments creates an empty list.
[]
[]
list()
[]
Use len to get the number of items in a list, also known as the length.
len(brands)
3
len([])
0
Python allows you to break lines within parentheses, brackets, or braces.
brands = [
"Fender",
"Gibson",
"Ibanez"
]
The Style Guide for Python Code discusses formatting conventions like these to make your code readable. [PEP008]