truediv()#

relationalai.Producer
Producer.__truediv__(other: Any) -> Expression

Returns an Expression that produces the quotient of the Producer values and other.

Parameters#

NameTypeDescription
otherAnyA numeric value or another Producer object.

Returns#

An Expression object.

Example#

A Producer object may be divided by a numeric literal:

import relationalai as rai

model = rai.Model("people")
Person = model.Type("Person")

with model.rule():
    Person.add(name="Fred", age=39)
    Person.add(name="Wilma", age=36)

with model.query() as select:
    person = Person()
    # `person.age` returns an `InstanceProperty` object,
    # which is also a `Producer` object.
    percent_life_completed = person.age / 76
    response = select(person.name, percent_life_completed)

print(response.results)
# Output:
#     v
#     name         v
# 0   Fred  0.513158
# 1  Wilma  0.473684

You may also divide two Producer objects:

with model.rule():
    fred = Person(name="Fred")
    fred.set(savings=200.0, savings_goal=1000.0)

with model.rule():
    wilma = Person(name="Wilma")
    wilma.set(savings=300.0, savings_goal=500.0)

with model.query() as select:
    person = Person()
    # `person.savings`, and `person.savings_goal`return
    # `InstanceProperty` objects, which are also `Producer` objects.
    percent_goal_completed = savings / savings_goal
    response = select(person.name, percent_goal_completed)

print(response.results)
# Output:
#     name    v
# 0   Fred  0.2
# 1  Wilma  0.6

See Also#