Python Dictionary items()-Methode

Python 字典Python-Wörterbuch


Beschreibung

Die Python-Dictionary-Methode items() gibt eine Liste durchlaufbarer (Schlüssel, Wert)-Tupelpaare zurück.

Syntax

Die Syntax der items()-Methode ist:

dict.items()

Parameters

  • Nicht zutreffend.

Rückgabewert

Gibt eine Liste durchlaufbarer (Schlüssel, Wert)-Tupelpaare zurück.

Beispiel

Das folgende Beispiel zeigt, wie man die items()-Methode verwendet:

Beispiel (Python 2.0+)

#!/usr/bin/python # coding=utf-8 tinydict = {'Google': 'www.google.com', 'Beispiel': 'www.example.com', 'taobao': 'www.taobao.com'} print "Wörterbuchwerte: %s" % tinydict.items() # Durchlaufe die Wörterbuchliste for key,values in tinydict.items(): print key,values

Die Ausgabe des obigen Beispiels ist:

字典值 : [('Google', 'www.google.com'), ('taobao', 'www.taobao.com'), ('Example', 'www.example.com')]
Google www.google.com
taobao www.taobao.com
Example www.example.com

Python 字典Python-Wörterbuch

Andere Erweiterungen