** * This article is from Udemy "[Introduction to Python3 taught by active Silicon Valley engineers + application + American Silicon Valley style code style](https://www.udemy.com/course/python-beginner/" Introduction to Python3 taught by active Silicon Valley engineers + application + American Silicon Valley style code style ")" It is a class notebook for myself after taking the course of. It is open to the public with permission from the instructor Jun Sakai. ** **
>>> d = {'x': 10, 'y': 20}
>>> d
{'x': 10, 'y': 20}
>>> type(d)
<class 'dict'>
By enclosing it with {}
, it becomes a dictionary type.
>>> d = {'x': 10, 'y': 20}
>>> d['x']
10
>>> d['y']
20
You can search the contents of the dictionary by using []
.
>>> d = {'x': 10, 'y': 20}
>>> d['x'] = 100
>>> d
{'x': 100, 'y': 20}
The value of the specified key can be rewritten with a new value.
>>> d = {'x': 10, 'y': 20}
>>> d['z'] = 100
>>> d
{'x': 10, 'y': 20, 'z': 100}
You can also add a new key.
>>> dict(a = 10, b = 20)
{'a': 10, 'b': 20}
>>> dict([('a', 10), ('b', 20)])
{'a': 10, 'b': 20}
for your information.
Recommended Posts