Skip to content

Instantly share code, notes, and snippets.

@bockor
Created December 11, 2024 12:36
Show Gist options
  • Save bockor/0cd1b3bfe213b0708ee82267c60574ec to your computer and use it in GitHub Desktop.
Save bockor/0cd1b3bfe213b0708ee82267c60574ec to your computer and use it in GitHub Desktop.
namedtuple new style
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