Python字典copy()
方法用于返回字典的浅拷贝。
语法
以下是copy()
方法的语法 -
dict.copy()
参数
- NA
返回值
- 此方法返回字典的浅拷贝。
示例
以下示例显示copy()
方法的用法 -
#!/usr/bin/python3
dict1 = {'Name': 'Maxsu', 'Age': 7, 'Class': 'First'}
dict2 = dict1.copy()
print ("New Dictionary : ",dict2)
当运行上面的程序,它产生以下结果 -
New dictionary : {'Name': 'Maxsu', 'Age': 7, 'Class': 'First'}
上一篇:
Python字典
下一篇:
Python日期和时间