Created
December 11, 2024 12:36
-
-
Save bockor/0cd1b3bfe213b0708ee82267c60574ec to your computer and use it in GitHub Desktop.
namedtuple new style
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import NamedTuple | |
class PJ (NamedTuple): | |
make: str | |
model: str | |
color: str | |
straps: int | |
price: float | |
stars: int | |
@property | |
def get_price_with_vat(self, vat=20.0): | |
return self.price + vat | |
pj1 = PJ("Laguna","Saphire", "BLK", 6, 83.77, 2) | |
print(f'Your choice: {pj1.make} / { pj1.model} which costs {pj1.get_price_with_vat} VAT included') | |
""" | |
prints | |
Your choice: Laguna / Saphire which costs 103.77 VAT included | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment