python 示例
字典clear()方法 (Dictionary clear() Method)
clear() method is used to clear all elements of the dictionary.
clear()方法用于清除字典中的所有元素。
Syntax:
句法:
dictionary_name.clear()
Parameter(s):
参数:
It does not accept any parameter.
它不接受任何参数。
Return value:
返回值:
The return type of this method is <class 'NoneType'>, it returns nothing.
此方法的返回类型为<class'NoneType'> ,它什么也不返回。
Example:
例:
# Python Dictionary clear() Method with Example
# dictionary declaration
student = {
"roll_no": 101,
"name": "Shivang",
"course": "B.Tech",
"per" : 98.5
}
# printing dictionary
print("data before clearing...")
print(student)
# clearing dictionary
student.clear()
# printing dictionary after clear()
print("data after clearing...")
print(student)
Output
输出量
data before clearing...
{'course': 'B.Tech', 'roll_no': 101, 'per': 98.5, 'name': 'Shivang'}
data after clearing...
{}
翻译自: https://www.includehelp.com/python/dictionary-clear-method-with-example.aspx
python 示例