Python Tips & Tricks : 1

Sagar Lad
Dec 22, 2022

1) Assertion

· Inform developers about unrecoverable errors in a program.

· Internal self-checks for program.

· They work by declaring some conditions as impossible .

def apply_discount(product, discount):

price = int(product[‘price’] * (1.0 discount))

assert 0 <= price <= product[‘price’]

return price

Python’s Assert Syntax

--

--