直接赋值方式
# 直接赋值
>>> mylist = ["list","tuple","str"]
# 创建空列表
>>> mylist1 = []
# 创建空列表
>>> mylist2 = list()
>>> mylist2
[]
>>>
转换方法
# 元祖转列表
>>> mytuple = ("a","b")
>>> type(mytuple)
<class 'tuple'>
>>> list(mytuple)
['a', 'b']
# 字符串转列表
>>> mystr = "abc"
>>> type(mystr)
<class 'str'>
>>> list(mystr)
['a', 'b', 'c']
>>>
# 集合转列表,由于集合是无序的,生成的列表元素顺序会改变
>>> mytuple = {'a','b'}
>>> type(mytuple)
<class 'set'>
>>> list(mytuple)
['b', 'a']
>>>
# 字典的键转换为列表
>>> mydict = {'age':18,'name':'zhangsan'}
>>> list(mydict)
['age', 'name']
>>>
# 字典的键值转化为字典
>>> list(mydict.items())
[('age', 18), ('name', 'zhangsan')]
>>>
# 生成器的方式生成列表
>>> list(range(10))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>>
split方法(只能将字符串转换成列表)
>>> mystr = "www.baidu.com"
>>> mystr.split('.',2)
['www', 'baidu', 'com']
>>>