python 示例_Python使用示例设置clear()方法

python 示例

设置clear()方法 (Set clear() Method)

clear() method is used to clear/remove all elements of the set.

clear()方法用于清除/删除集合中的所有元素。

Syntax:

句法:

    set_name.clear()

Parameter(s):

参数:

  • It does not accept any parameter.

    它不接受任何参数。

Return value:

返回值:

The return type of this method is None.

此方法的返回类型为None 。

Example:

例:

# Python Set clear() Method with Example

# declaring a set
cities = {"New Delhi", "Mumbai", "Indore", "Gwalior"}

# printing set before clearing the element
print("cities = ", cities)

# clearing all elements
cities.clear()

# printing set after clearing the element
print("cities = ", cities)

Output

输出量

cities =  {'Indore', 'Gwalior', 'New Delhi', 'Mumbai'}
cities =  set()


翻译自: https://www.includehelp.com/python/set-clear-method-with-example.aspx

python 示例