← 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)))
- A.Book(title='DSA', price=399)
- B.('DSA', 399)
- C.{'title': 'DSA', 'price': 399}
- 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 →