Check your understanding of the previous reading: functions that build, mutate, and convert dataclass instances.
Which of the following statements is true?
Select every option that applies, then check.
parse_card in the reading, a function can build and return a dataclass instance.area in the reading, a function can take a dataclass instance as a parameter.str(rect.length)).Given the code below:
from dataclasses import dataclass
from bakery import assert_equal
@dataclass
class Wallet:
cash: int
cards: int
def add_wallets(left: Wallet, right: Wallet) -> __1__:
return Wallet(
left.cash + right.cash,
__2__ + __3__
)
assert_equal(add_wallets(Wallet(5, 10), Wallet(3, 2)), Wallet(8, 12))
The add_wallets function's return type (__1__) should be . The second argument to the returned Wallet (__2__ + __3__) should add and .
add_wallets builds and returns a new Wallet, so its return type is the dataclass itself. The first field already sums the two cash fields (left.cash + right.cash) - the second field should do the same thing for the other field, cards.
add_wallets returns a Wallet. The second argument adds left.cards and right.cards, matching the pattern used for cash in the first argument.