Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Challenge: Mastering Dictionary Unpacking in Python | Mastering Packing and Unpacking in Python
Intermediate Python Techniques

book
Challenge: Mastering Dictionary Unpacking in Python

Oppgave

Swipe to start coding

Simply unpack the dictionary with personal information and don't use loops for that.

  1. Use name, age, city variables to unpack the dictionary;
  2. Use values() dictionary method;
  3. Print all info.

Løsning

person_info = {'name': 'John', 'age': 35, 'city': 'New York'}

name, age, city = person_info.values()

print("Name:", name)
print("Age:", age)
print("City:", city)

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 1. Kapittel 4
person_info = {'name': 'John', 'age': 35, 'city': 'New York'}

___, ___, ___ = person_info.___

print("Name:", name)
print("Age:", ___)
print("City:", ___)

toggle bottom row
some-alt