English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Python basic tutorial

Python flow control

Fonctions en Python

Types de données en Python

Python file operations

Python objects and classes

Python date and time

Advanced knowledge of Python

Python reference manual

Python set clear() usage and examples

Méthodes de collections en Python

The clear() method removes all elements from the set.

The syntax of the clear() method is:

set.clear()

clear() parameters

The clear() method does not take any parameters.

clear() return value

The clear() method does not return any value and returns'None'.

Example1: Use clear() to remove all elements from a Python set

# Set 
vowels = {'a', 'e', 'i', 'o', 'u'}
print('Vowels (before clearing):', vowels)
# Clear vowels
vowels.clear()
print('Vowels (after clearing):', vowels)

When running the program, the output is:

Vowels (before clearing): {'o', 'i', 'e', 'u', 'a'}
Vowels (after clearing): set()

Méthodes de collections en Python