Python语言基础
Python语言进阶
Python数据结构

Python dictionary clear()方法

搞懂Python dictionary clear()方法的用法

描述

Python 字典 clear() 函数用于删除字典内所有元素。

语法

clear()方法语法:
dict.clear()

参数

NA。

返回值

该函数没有任何返回值。

实例

以下实例展示了 clear()函数的使用方法:
dict = {'Name': 'Lidihuo', 'Age': 2}
print ("字典长度 : %d" % len(dict))
dict.clear()
print ("字典删除后长度 : %d" % len(dict))
以上实例输出结果为:
字典长度 : 2
字典删除后长度 : 0
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4