python3 list list()方法
描述
list() 方法用于将元组或字符串转换为列表。
注:元组与列表是非常类似的,区别在于元组的元素值不能修改,元组是放在括号中,列表是放于方括号中。
语法
list()方法语法:
list( seq )
参数
- seq -- 要转换为列表的元组或字符串。
返回值
返回列表。
实例
以下实例展示了 list()函数的使用方法:
#!/usr/bin/python3
atuple = (123, 'google', '51frw', 'taobao')
list1 = list(atuple)
print ("列表元素 : ", list1)
str="hello world"
list2=list(str)
print ("列表元素 : ", list2) 以上实例输出结果如下:
列表元素 : [123, 'google', '51frw', 'taobao'] 列表元素 : ['h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd']
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!