Home » Python

Python Dictionary clear() Method with Example

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

Dictionary clear() Method

clear() method is used to clear all elements of the dictionary.

Syntax:

    dictionary_name.clear()

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of this method is <class 'NoneType'>, it returns nothing.

Example:

# Python Dictionary clear() Method with Example

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

# printing dictionary
print("data before clearing...")
print(student)

# clearing dictionary
student.clear()

# printing dictionary after clear()
print("data after clearing...")
print(student)

Output

data before clearing...
{'course': 'B.Tech', 'roll_no': 101, 'per': 98.5, 'name': 'Shivang'}
data after clearing...
{}






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.