创新互联python教程:

编写一个 Python 程序,通过一个实际例子将键值对添加到字典中。
在这个 python 程序中,我们使用字典更新功能将键值插入到字典中。
# Python Program to Add Key-Value Pair to a Dictionary
key = input("Please enter the Key : ")
value = input("Please enter the Value : ")
myDict = {}
# Add Key-Value Pair to a Dictionary in Python
myDict.update({key:value})
print("\nUpdated Dictionary = ", myDict)
这个 Python 程序是将键值插入字典的另一种方法。
# Python Program to Add Key-Value Pair to a Dictionary
key = input("Please enter the Key : ")
value = input("Please enter the Value : ")
myDict = {}
# Add Key-Value Pair to a Dictionary in Python
myDict[key] = value
print("\nUpdated Dictionary = ", myDict)向字典输出添加键值对
Please enter the Key : M
Please enter the Value : Mango
Updated Dictionary = {'M': 'Mango'} 
售后响应及时
7×24小时客服热线
数据备份
更安全、更高效、更稳定
价格公道精准
项目经理精准报价不弄虚作假
合作无风险
重合同讲信誉,无效全额退款