🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Type Hints and Dataclasses: all 10 questions

Quiz: Type Hints and Dataclasses · Question 10 of 10

What does this print? (code)

What does this print?

from dataclasses import dataclass, asdict
@dataclass
class Book:
    title: str
    price: int
print(asdict(Book("DSA", 399)))
  1. A.Book(title='DSA', price=399)
  2. B.('DSA', 399)
  3. C.{'title': 'DSA', 'price': 399}
  4. D.An error
Answer & explanation

Correct answer: {'title': 'DSA', 'price': 399}

asdict converts the fields into a plain dictionary.

Can you get the rest right without peeking?

Take the timed Quiz: Type Hints and Dataclasses quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →