python中创建列表、元组、字符串、字典、集合

1、列表 -- (中括号 + 逗号)

>>> a = ["aaa","bbb","ccc","ddd"]
>>> a
['aaa', 'bbb', 'ccc', 'ddd']
>>> type(a)
<class 'list'>

2、元组 -- (小括号 + 逗号)

>>> a = ("a","b","c","d")
>>> a
('a', 'b', 'c', 'd')
>>> type(a)
<class 'tuple'>

3、字符串 -- (引号)

>>> a = "helloworld"
>>> a
'helloworld'
>>> type(a)
<class 'str'>

4、字典 --(键值对)

>>> a = {"a":111,"b":222,"c":333,"d":444}
>>> a
{'a': 111, 'b': 222, 'c': 333, 'd': 444}
>>> type(a)
<class 'dict'>

5、集合 -- (唯一)

>>> a = {1,2,3,4,5}
>>> a
{1, 2, 3, 4, 5}
>>> type(a)
<class 'set'>
原文地址:https://www.cnblogs.com/liujiaxin2018/p/14470094.html