112 days ago · Tech · hide · Fediverse post

Python A-Z is a blog series about Python. Each day, I share insights, ideas and examples for different parts of Python development that match with the letter of the day. Blaugust is an annual blogging festival in August where the goal is to write a blog post every day of the month. The assert statement is a built-in Python statement that gives developers a nice short hand for raising an AssertionError based on a condition. assert expression, "message" An assert statement is syntactic shorthand for if __debug__: if not expression: raise AssertionError("message") To see how it works in practice, let’s jump into a REPL session: >>> age = 21 >>> assert age > 18, f"Needs to be over 18 years old, {age=}" >>> age = 16 >>> assert age > 18, f"Needs to be over 18 years old, {age=}" Traceback (most recent call last): File "<python-input-5>", line 1, in <module> assert age > 18, f"Needs to be over 18 years old, {age=}" ^^^^^^^^ AssertionError: Needs to be over 18 years old, age=16 When the…

Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town