Loading section...

Creating Lists

Concepts: pyListCreate

Every list in Python is defined using square brackets: [ and ]. These brackets tell Python that you are creating a list rather than some other type of data. Inside the brackets, you place the items you want to store, separated by commas. Each comma acts as a divider between individual items. In the first example, we create a list called numbers containing five integers. The square brackets wrap around all five values, and commas separate each value from the next. In the second example, we create a list of three strings. Notice that when Python prints strings, it shows them with quotes to indicate they are text rather than numbers. Empty Lists Sometimes you need to create a list that starts with no items. This is called an empty list. You might do this when you plan to add items later, perh