Python3 字典 clear()方法

Python 3 教程 · 2019-02-06 14:58:01

描述

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

语法

clear()方法语法:

dict.clear()

参数

  • NA。

返回值

该函数没有任何返回值。

实例

以下实例展示了 clear()函数的使用方法:

#!/usr/bin/python3

dict = {'Name': 'Zara', 'Age': 7}

print ("字典长度 : %d" %  len(dict))
dict.clear()
print ("字典删除后长度 : %d" %  len(dict))

以上实例输出结果为:

字典长度 : 2
字典删除后长度 : 0

点击查看所有 Python 3 教程 文章: https://codercto.com/courses/l/10.html

查看所有标签

Numerical Recipes 3rd Edition

Numerical Recipes 3rd Edition

William H. Press、Saul A. Teukolsky、William T. Vetterling、Brian P. Flannery / Cambridge University Press / 2007-9-6 / GBP 64.99

Do you want easy access to the latest methods in scientific computing? This greatly expanded third edition of Numerical Recipes has it, with wider coverage than ever before, many new, expanded and upd......一起来看看 《Numerical Recipes 3rd Edition》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具