字符串
In [1]:
a = 'python'
集合
In [2]:
b = {1, 2, 3}
元组
In [3]:
c = (1, 2, 3)
In [4]:
print(list(a))
['p', 'y', 't', 'h', 'o', 'n']
In [5]:
print(list(b))
[1, 2, 3]
In [6]:
print(list(c))
[1, 2, 3]
输出结果是:
['p', 'y', 't', 'h', 'o', 'n']
[1, 2, 3]
[1, 2, 3]list 函数能否将字典转换成列表呢,这个需要探索一下。
In [3]:
print(list({'a': 3, 'b': 5}))
['a', 'b']
输出结果为:
['a', 'b']字符串
In [8]:
a = 'python'
列表
In [9]:
b = [1, 2, 1, 2]
字典
In [10]:
c = {'a': 1, 'b': 2}
元组
In [11]:
d = (1, 2, 3, 4)
In [12]:
print(set(a))
{'n', 'o', 'p', 't', 'y', 'h'}
In [13]:
print(set(b))
{1, 2}
In [14]:
print(set(c))
{'b', 'a'}
In [15]:
print(set(d))
{1, 2, 3, 4}
程序输出结果:
{'n', 'o', 'p', 't', 'y', 'h'}
{1, 2}
{'b', 'a'}
{1, 2, 3, 4}字符串
In [16]:
a = 'python'
列表
In [17]:
b = [1, 2, 1, 2]
字典
In [18]:
c = {'a': 1, 'b': 2}
集合
In [19]:
d = {1, 2, 3, 4}
In [20]:
print(tuple(a))
('p', 'y', 't', 'h', 'o', 'n')
In [21]:
print(tuple(b))
(1, 2, 1, 2)
In [22]:
print(tuple(c))
('a', 'b')
In [23]:
print(tuple(d))
(1, 2, 3, 4)
程序输出结果:
('p', 'y', 't', 'h', 'o', 'n')
(1, 2, 1, 2)
('a', 'b')
(1, 2, 3, 4)In [6]:
my_dict = dict(a=1, b=2)
print(my_dict)
{'a': 1, 'b': 2}
程序输出结果:
{'a': 1, 'b': 2}