Home > Article > Backend Development > How to use the python items() method
How to use the python items() method?
Python Dictionary (Dictionary) items() method
Python Dictionary (Dictionary) items() function returns a traversable (key, value) in a list Array of tuples.
Recommended: "Python Tutorial"
Grammar
##items() method syntax:dict.items()Parameter NA. Return valueReturns a traversable array of (key, value) tuples. The following example shows how to use the items() function: Example (Python 2.0)
#!/usr/bin/python # coding=utf-8 dict = {'Google': 'www.google.com', 'Runoob': 'www.php.cn', 'taobao': 'www.taobao.com'} print "字典值 : %s" % dict.items() # 遍历字典列表 for key,values in dict.items(): print key,valuesThe output result of the above example is:
字典值 : [('Google', 'www.google.com'), ('taobao', 'www.taobao.com'), ('Runoob', 'www.php.cn')] Google www.google.com taobao www.taobao.com php www.php.cn
The above is the detailed content of How to use the python items() method. For more information, please follow other related articles on the PHP Chinese website!