From the course: Python Quick Start

Unlock this course with a free trial

Join today to access over 24,500 courses taught by industry experts.

Using lists in Python

Using lists in Python - Python Tutorial

From the course: Python Quick Start

Using lists in Python

When you're programming, you might find yourself wanting to store a number for you to use later in your code. Say that number is 5. You can store it by doing something like this. I can create a variable named "n" and give it a value of 5. So whenever I refer to n, I have access to the Number, 5. I'm going to run this cell and in the next cell, I can print out "n" And when I run this, 5 gets printed out. Now, if you want to store multiple numbers together, Python has a clever way of doing this using something called a sequence. A sequence allows you to store a collection of data. One type of sequence is called a list. A list has a specific order, and the items in the list can be changed whenever you want. Square brackets are used to enclose the items in the list and commas are used to separate the items from each other. So you can create a list containing the numbers you have and store the list in a variable. If your numbers are 5, 10, 15, and 20, it would look something like this. I…

Contents