首页 > 其他 > 详细

A list is a sequence

时间:2014-07-11 09:00:44      阅读:340      评论:0      收藏:0      [点我收藏+]

Like a string, a list is a sequence of values. In a string, the values are characters; in a list, they can be any type. The values in list are called elements or sometimes items. There are several ways to create a new list; the simplest is to enclose the elements in square brackets ( [ ]):

[10, 20, ‘span’, [30,40]]

A list within another list is said to be nested. A list that contains no elements is called an empty list; you can create one with empty brackets, []. List that contain consecutive integers are common, so Python provides a built-in function to create them:

  bubuko.com,布布扣                     

range takes two arguments and returns a list that contains all the integers from the first to the second, including the first but excluding the second! With one argument, range starts at 0:

 bubuko.com,布布扣

If there is a third argument, it specifies the space between successive values, which is called the ‘step size’.

 bubuko.com,布布扣

 

from Thinking in Python

A list is a sequence,布布扣,bubuko.com

A list is a sequence

原文:http://www.cnblogs.com/ryansunyu/p/3834584.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!