Python Set clear() Method

Python3 列表Python Set


Description

The clear() method is used to remove all elements from a set.

Syntax

The syntax of the clear() method is:

set.clear()

Parameters

  • None.

Return Value

None.

Examples

Remove all elements from the fruits set:

Example 1

fruits = {"apple", "banana", "cherry"} fruits.clear() print(fruits)

The output result is:

set()

Python3 列表Python Set

Other Extensions