码迷,mamicode.com
首页 > 编程语言 > 详细

Python内置函数(38)——list

时间:2016-11-04 23:04:55      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:scn   desc   cti   str   table   python   tle   seq   util   

英文文档:

class list([iterable])

Rather than being a function, list is actually a mutable sequence type, as documented in Lists and Sequence Types — list, tuple, range

 

说明:

  1. list函数,实际是上列表类型的构造函数。

  2. 可以不传入任何参数,结果返回一个空列表。

>>> a = list()
>>> a
[]

  3. 可以传入一个可迭代对象,如字符串,字节数组、元组、列表、range对象,结果将返回可迭代对象中元素组成的列表。

>>> list(abcd) # 字符串
[a, b, c, d]
>>> list(bytes(abcd,utf-8)) # 字节数组
[97, 98, 99, 100]
>>> list((a,b,c,d)) # 元组
[a, b, c, d]
>>> list([a,b,c,d]) # 列表
[a, b, c, d]
>>> list(range(1,5)) # range对象
[1, 2, 3, 4]

 

Python内置函数(38)——list

标签:scn   desc   cti   str   table   python   tle   seq   util   

原文地址:http://www.cnblogs.com/sesshoumaru/p/6031551.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!