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

Python basic tutorial

Python flow control

Função do Python

Tipos de Dados do Python

Python file operations

Python objects and classes

Python date and time

Advanced knowledge of Python

Python reference manual

Python set clear() usage and example

Métodos de Conjunto do 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étodos de Conjunto do Python