Breaking News

list in Python

 

What Is a List?

list is a collection of items in a particular order. You can make a list that includes the letters of the alphabet, the digits from 0–9, or the names of all the people in your family. You can put anything you want into a list, and the items in your list don’t have to be related in any particular way. Because a list usually contains more than one element, it’s a good idea to make the name of your list plural, such as lettersdigits, or names.

In Python, square brackets ([]) indicate a list, and individual elements in the list are separated by commas. Here’s a simple example of a list that contains a few kinds of bicycles:

bicycles.py

bicycles = ['trek', 'cannondale', 'redline', 'specialized']
print(bicycles)

If you ask Python to print a list, Python returns its representation of the list, including the square brackets:

['trek', 'cannondale', 'redline', 'specialized']

No comments