ReQL command: ~, not_
Command syntax
bool.not_() → bool not_(bool) → bool (~bool) → bool
Description
Compute the logical inverse (not) of an expression.
not_
can be called either via method chaining, immediately after an expression that evaluates as a boolean value, or by passing the expression as a parameter to not_
. All values that are not False
or None
will be converted to True
.
You may also use ~
as a shorthand operator.
Example: Not true is false.
r.not_(True).run(conn)
r.expr(True).not_().run(conn)
(~r.expr(True)).run(conn)
These evaluate to false
.
Note that when using ~
the expression is wrapped in parentheses. Without this, Python will evaluate r.expr(True)
first rather than using the ReQL operator and return an incorrect value. (~True
evaluates to −2 in Python.)
Example: Return all the users that do not have a “flag” field.
r.table('users').filter(
lambda users: (~users.has_fields('flag'))
).run(conn)
Example: As above, but prefix-style.
r.table('users').filter(
lambda users: r.not_(users.has_fields('flag'))
).run(conn)
© RethinkDB contributors
Licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License.
https://rethinkdb.com/api/python/not/