“Wörterbuch erhalten sowohl Schlüssel als auch Wert.” Code-Antworten

Wörterbuch erhalten sowohl Schlüssel als auch Wert.

# Loop thru a dictionary, get both key and value.

dd = {'john':3, 'mary':4, 'joe':5, 'vicky':7}

for kk, vv in dd.items():
    print(kk, ' is ', vv)

# john  is  3
# mary  is  4
# joe  is  5
# vicky  is  7
Sore Sloth

Wörterbuch erhalten sowohl Schlüssel als auch Wert.

# get value of given key

hh = {"a":1, "b":2}

print(hh.get("b")) # 2

print(hh.get("x")) # None

print(hh.get("x", 8)) # 8
Sore Sloth

Ähnliche Antworten wie “Wörterbuch erhalten sowohl Schlüssel als auch Wert.”

Fragen ähnlich wie “Wörterbuch erhalten sowohl Schlüssel als auch Wert.”

Weitere verwandte Antworten zu “Wörterbuch erhalten sowohl Schlüssel als auch Wert.” auf Python

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen