这篇教程Python 字典(Dictionary) len()方法写得很实用,希望能帮到您。 描述Python 字典(Dictionary) len() 函数计算字典元素个数,即键的总数。 语法len()方法语法: len(dict) 参数返回值返回字典的元素个数。 实例以下实例展示了 len()函数的使用方法: #!/usr/bin/pythondict = {'Name': 'Zara', 'Age': 7};print "Length : %d" % len (dict) 以上实例输出结果为: Length : 2 Python 字典(Dictionary) cmp()方法 Python 字典(Dictionary) str()方法 |