How to Use Set clear() Method in PythonPython Basics


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.

© 2024 Cheerlearn.com, all rights reserved. Privacy Policy | Contact Us