Home » Python

Python Dictionary copy() Method with Example

Python Dictionary copy() Method: Here, we are going to learn how to copy a dictionary using copy() method?
Submitted by IncludeHelp, on November 25, 2019

Dictionary copy() Method

copy() method is used to copy a dictionary, it returns the copy of this dictionary.

Syntax:

    dictionary_name.copy()

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of this method is <class 'dict'>, it returns the dictionary.

Example:

# Python Dictionary copy() Method with Example

# dictionary declaration
student = {
  "roll_no": 101,
  "name": "Shivang",
  "course": "B.Tech",
  "per" : 98.5
}

# printing dictionary
print("data of student dictionary...")
print(student)

# copying dictionary
student_x = student.copy()

# printing dictionary
print("data of student_x dictionary...")
print(student_x)

Output

data of student dictionary...
{'roll_no': 101, 'course': 'B.Tech', 'name': 'Shivang', 'per': 98.5}
data of student_x dictionary...
{'roll_no': 101, 'course': 'B.Tech', 'name': 'Shivang', 'per': 98.5}






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.