Skip to content

Instantly share code, notes, and snippets.

@jftuga
Created March 7, 2023 02:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jftuga/959a6d2566d8cbde94dc739fed941605 to your computer and use it in GitHub Desktop.
Save jftuga/959a6d2566d8cbde94dc739fed941605 to your computer and use it in GitHub Desktop.
Python Decorator
# source: https://www.pythontutorial.net/advanced-python/python-decorators/
def currency(fn):
def wrapper(*args, **kwargs):
result = fn(*args, **kwargs)
return f'${result}'
return wrapper
@currency
def net_price(price, tax):
""" calculate the net price from price and tax
Arguments:
price: the selling price
tax: value added tax or sale tax
Return
the net price
"""
return price * (1 + tax)
print(net_price(100, 0.05)) # output: $105.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment