首页 > 编程语言 > 详细

Python内置函数(38)——list

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

英文文档:

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

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

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