Home » Python

Python Set clear() Method with Example

Python Set clear() Method: Here, we are going to learn how to clear/remove all elements of the set in Python?
Submitted by IncludeHelp, on November 27, 2019

Set clear() Method

clear() method is used to clear/remove all elements of the set.

Syntax:

    set_name.clear()

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of this method is None.

Example:

# Python Set clear() Method with Example

# declaring a set
cities = {"New Delhi", "Mumbai", "Indore", "Gwalior"}

# printing set before clearing the element
print("cities = ", cities)

# clearing all elements
cities.clear()

# printing set after clearing the element
print("cities = ", cities)

Output

cities =  {'Indore', 'Gwalior', 'New Delhi', 'Mumbai'}
cities =  set()






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.