O'Reilly logo

Ubuntu Unleashed 2014 Edition: Covering 13.10 and 14.04,Ninth Edition by Paul Hudson, Andrew Hudson, Matthew Helmke

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Lists

Python’s built-in list data type is a sequence, like strings. However, they are mutable, which means you can change them. Lists are like arrays in that they hold a selection of elements in a given order. You can cycle through them, index into them, and slice them:

>>> mylist = ["python", "perl", "php"]>>> mylist['python', 'perl', 'php']>>> mylist + ["java"]["python", 'perl', 'php', 'java']>>> mylist * 2['python', 'perl', 'php', 'python', 'perl', 'php']>>> mylist[1]'perl'>>> mylist[1] = "c++">>> mylist[1]'c++'>>> mylist[1:3]['c++', 'php']

The brackets notation is important: You cannot use parentheses, (( and )) or braces ({ and }) for lists. Using + for lists is different from using + for numbers. Python detects ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required