首页 > 代码库 > Python内置函数(38)——list
Python内置函数(38)——list
英文文档:
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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。