{"id":25040,"date":"2021-11-10T09:37:07","date_gmt":"2021-11-10T04:07:07","guid":{"rendered":"https:\/\/python-programs.com\/?p=25040"},"modified":"2021-11-10T09:37:07","modified_gmt":"2021-11-10T04:07:07","slug":"python-dictionary-copy-function-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-dictionary-copy-function-with-examples\/","title":{"rendered":"Python Dictionary copy() Function with Examples"},"content":{"rendered":"

Dictionary copy() Function in Python:<\/strong><\/p>\n

The copy() method makes a duplicate of the specified dictionary(copy).<\/p>\n

Syntax:<\/strong><\/p>\n

dictionary.copy()<\/pre>\n

Parameters:<\/strong> This method doesn’t accept any parameters<\/p>\n

Return Value:<\/strong><\/p>\n

This method gives you a shallow copy of the dictionary. It makes no changes to the original dictionary.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given dictionary = {20: 'good', 30: 'morning', 40: 'btechgeeks'}<\/pre>\n

Output:<\/strong><\/p>\n

The given original dictionary is:\r\n{20: 'good', 30: 'morning', 40: 'btechgeeks'}\r\nThe copied new dictionary is:\r\n{20: 'good', 30: 'morning', 40: 'btechgeeks'}<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given dictionary = {'hello': 100, 'btechgeeks': 200}<\/pre>\n

Output:<\/strong><\/p>\n

The given original dictionary is:\r\n{'hello': 100, 'btechgeeks': 200}\r\nThe copied new dictionary is:\r\n{'hello': 100, 'btechgeeks': 200}<\/pre>\n

Dictionary copy() Function with Examples in Python<\/h2>\n