Python Set clear() MethodPython Functions

Difficulty Level:
Difficulty Level:

The clear() method is used to remove all elements in the set but remains the set.

Example

#!/usr/bin/python3
# -*- coding: UTF-8 -*-

Car = {"Mercedes-Benz", "Rolls-royce", "CADILLAC","Honda","Hyundai","Land Rover"}
print(Car)
Car.clear()
print(Car)

Output:

{'Mercedes-Benz', 'Hyundai', 'Honda', 'Rolls-royce', 'CADILLAC', 'Land Rover'}
set()

Syntax

set.clear()

Parameters

The method doesn’t take any parameters.

Return Value

It doesn’t return any value.

Advertisement

© 2021 Pythonexample.org, all rights reserved. Privacy Policy | Contact Us