Get the key value pair count in a Python dictionary

Key value pair count

len() returns the total number of items, that is, key-value pairs.


dict2 = {'name': 'earth', 'port': 80}
print dict2
print len(dict2)

The code above generates the following result.





















Home »
  Python »
    Data Types »




Data Types
String
String Format
Tuple
List
Set
Dictionary