
上QQ阅读APP看书,第一时间看更新
4.3.4 字典中的3个函数
字典包括3个函数,函数的名称及功能说明如表4.4所示。
表4.4 字典的函数名称及功能说明

字典的函数示例如下。
单击“开始”菜单,打开Python 3.6.5 Shell软件,输入dict1={'姓名': '张平', '年龄': 12, '年级': '6','学习成绩':'优'},按Enter键,再输入str(dict1),按Enter键,就可以看到以可打印的字符串表示的字典数据,如图4.15所示。

图4.15 以可打印的字符串表示的字典数据示例的运行结果
然后输入print("字典中元素个数,即键的总数:",len(dict1)),然后按Enter键,就可以显示字典中元素个数;然后再输入type(dict1),按Enter键,就可以看到字典数据类型,如图4.16所示。

图4.16 字典中的函数示例的运行结果