Raymond Hettinger’s quiz about: assert

Post written by A python enthusiast

Definition and Usage

The assert keyword is used when debugging code.

The assert keyword lets you test if a condition in your code returns True, if not, the program will raise an AssertionError.

You can write a message to be written if the code returns False, check the example below (w3school.com).

x = "hello"

#if condition returns False, AssertionError is raised:
assert x == "goodbye", "x should be 'hello'"

Inspired by Raymond Hettinger pop quiz

I checked out and made my guess:

>>> assert t == (1, 23), "\n========\nError: Not same tuple\n========="
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AssertionError:
========
Error: Not same tuple
=========


Subscribe to the newsletter for updates
Tkinter templates
My youtube channel

Twitter: @pythonprogrammi - python_pygame

Videos

Speech recognition game

Pygame's Platform Game

Other Pygame's posts