176k views
1 vote
PYTHON PROGRAMMERS HELP ASAP

Define a Type contract.

User Geekydel
by
7.7k points

2 Answers

6 votes
PyContracts is a Python package that allows to declare constraints on function parameters and return values. It supports a basic type system, variables binding, arithmetic constraints, and has several specialized contracts (notably for Numpy arrays).
User Yura Loginov
by
7.8k points
6 votes

Answer:

In Python programming, this is possible to define some specific constraints on function parameters and return values. To do so, we can make use of a Python package, PyContracts. PyContracts enables Python programmer to specify a particular variable type and arithmetic constrains on the function parameters and its return values.

There are three ways to use PyContracts packages:

  1. Using the ``@contract`` decorator
  2. Using annotations
  3. Using docstrings
User Marc Van Leeuwen
by
8.3k points