On this page
  1. ast.Assert
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

ast.Assert

Prev: ast.arguments | Up: ast | Next: ast.Assign
Rel: ast.Add, ast.alias, ast.And, ast.AnnAssign
Ref: docs.python.org — ast.Assert
Tags: #public #python3 #stdlib #ast


Import

import ast
from ast import Assert

Signature & Overview

ast.Assert(expr test, expr? msg)

Assert(expr test, expr? msg)

Usage

import ast

stmt = ast.parse("assert x > 0, 'positive'").body[0]
assert isinstance(stmt, ast.Assert) and stmt.msg is not None

Gotchas

REPL Inspect

from ast import Assert
help(Assert)

Linked from

Related notes