• Python: 3.8.11
  • OS: Ubuntu Kylin 20.04
  • Conda: 4.10.1
  • Jupyter lab: 3.1.4

code

# 1
my_dict = {'yellow emperor': 'Huangdi Neijing'.'Zhang Zhongjing': On febrile and miscellaneous Diseases}
my_dict

{'yellow emperor': 'Huangdi Neijing'.'Zhang Zhongjing': On febrile and miscellaneous Diseases}
Copy the code
# 2
my_dict = dict(((Huangfu Mi.'Acupuncture and Moxibustion A and B'), ('wu Tang'.'Febrile disease stripe discrimination')))
my_dict

{Huangfu Mi: 'Acupuncture and Moxibustion A and B'.'wu Tang': 'Febrile disease stripe discrimination'}
Copy the code
Create an empty dictionary
my_dict = {}
my_dict

{}
Copy the code
Create an empty dictionary
my_dict = dict()
my_dict

{}
Copy the code
# 5 Use keywords
my_dict = dict(Li Shizhen =Compendium of Materia Medica, Sun Simiao ='Precious gold essentials')
my_dict

{'Li Shizhen': Compendium of Materia Medica.'Sun Simiao': 'Precious gold essentials'}
Copy the code
# 6
my_dict = dict()
my_dict['que'] = 'Bianque Internal Meridian'
my_dict['Zhang Zhongjing'] = '????? '
my_dict

{'que': 'Bianque Internal Meridian'.'Zhang Zhongjing': '????? '}
Copy the code
# 7 Change the value of an existing key
print(my_dict)
my_dict['Zhang Zhongjing'] = 'Synopsis of golden Chamber'
my_dict

{'que': 'Bianque Internal Meridian'.'Zhang Zhongjing': '????? '}
{'que': 'Bianque Internal Meridian'.'Zhang Zhongjing': 'Synopsis of golden Chamber'}
Copy the code
print(my_dict)
my_dict.clear()
my_dict

{'que': 'Bianque Internal Meridian'.'Zhang Zhongjing': 'Synopsis of golden Chamber'}
{}
Copy the code
Generate a dictionary with odd values True and even values False up to 10
dic = {i: i % 2! =0 for i in range(1.10)}
dic

{1: True.2: False.3: True.4: False.5: True.6: False.7: True.8: False.9: True}
Copy the code

Learning to recommend

  • Python documentation – English
  • Python documentation – Chinese
  • Python code PEP
  • Google version of the Python specification
  • Python source code
  • Python PEP
  • Optimal kirin
  • The nuggets platform
  • Gitee platform


Python is open source, cross-platform, interpretive, interactive, and worth learning. Python’s design philosophy: elegant, unambiguous, simple. Advocate one way, preferably only one way to do one thing. Code should be written in accordance with specifications to facilitate communication and understanding. Every language has its own unique ideas. Beginners need to change their thinking, practice and accumulate.