Python3 字典 copy()方法

Python3 字典 Python3 字典


描述

Python 字典 copy() 函數(shù)返回一個(gè)字典的淺復(fù)制。

語法

copy()方法語法:

dict.copy()

參數(shù)

  • NA。

返回值

返回一個(gè)字典的淺復(fù)制。

實(shí)例

以下實(shí)例展示了 copy()函數(shù)的使用方法:

#!/usr/bin/python3

dict1 = {'Name': 'W3CSchool', 'Age': 7, 'Class': 'First'}

dict2 = dict1.copy()
print ("新復(fù)制的字典為 : ",dict2)

以上實(shí)例輸出結(jié)果為:

新復(fù)制的字典為 :  {'Age': 7, 'Name': 'W3CSchool', 'Class': 'First'}

Python3 字典 Python3 字典