python2和python3中的dict

python2和python3的dict

将object转换为dict

vars([object]) -> dictionary

python2 dict

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
m_dict = {'a': 10, 'b': 20}

values = m_dict.values()
print(type(values))
print(values)
print("\n")

items = m_dict.items()
print(type(items))
print(items)
print("\n")

keys = m_dict.keys()
print(type(keys))
print(keys)
print("\n")

l_values = list(values)
print(type(l_values))
print(l_values)

输出:

python3 dict

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
m_dict = {'a': 10, 'b': 20}

values = m_dict.values()
print(type(values))
print(values) print("\n")

items = m_dict.items()
print(type(items))
print(items)
print("\n")

keys = m_dict.keys()
print(type(keys))
print(keys)
print("\n")

l_values = list(values)
print(type(l_values))
print(l_values)

输出: