Python Glossary Русский

all Python 3astterm

ast.FloorDiv

operators

The class of the floor division operator //: a FloorDiv() instance sits in the op of a BinOp or an AugAssign (a //= b).

Syntax

ast.FloorDiv()  # //

FloorDiv rounds down, not toward zero, though the tree does not show it — the node only names the operator; -7 // 2 is -4. Plain division / is the Div class and the remainder % is Mod; divmod(a, b) is a function Call, not a BinOp at all. The node has no fields.

Examples

import ast
node = ast.parse('-7 // 2', mode='eval').body
print(type(node.op).__name__, type(node.left).__name__)  # → FloorDiv UnaryOp
print(eval(compile(ast.Expression(node), '<x>', 'eval')))  # → -4

See also

Open in the full glossarydocs.python.orgReport an inaccuracy